Мне нужно торговать на прорыве зигзага после выполнения некоторых условий, как на скриншоте...
Это код, который я написал:
Код: Выделить всё
// Copyright QUANTOWER LLC. © 2017-2023. All rights reserved.
using System;
using System.Collections.Generic;
using TradingPlatform.BusinessLayer;
namespace ZigZag_BREAKOUT
{
///
/// An example of strategy for working with one symbol. Add your code, compile it and run via Strategy Runner panel in the assigned trading terminal.
/// Information about API you can find here: http://api.quantower.com
///
public class ZigZag_BREAKOUT : Strategy
{
[InputParameter("Symbol", 10)]
private Symbol symbol;
[InputParameter("Account", 20)]
public Account account;
public override string[] MonitoringConnectionsIds => new string[] { this.symbol?.ConnectionId };
public ZigZag_BREAKOUT()
: base()
{
// Defines strategy's name and description.
this.Name = "ZigZag_BREAKOUT";
this.Description = "My strategy's annotation";
}
///
/// This function will be called after creating a strategy
///
protected override void OnCreated()
{
// Add your code here
}
///
/// This function will be called after running a strategy
/// beforeLastSwing && lastSwing != highs[0])
{
highs[3] = highs[2];
highs[2] = highs[1];
highs[1] = highs[0];
highs[0] = lastSwing;
}
else if (lastSwing < beforeLastSwing && lastSwing != lows[0])
{
lows[3] = lows[2];
lows[2] = lows[1];
lows[1] = lows[0];
lows[0] = lastSwing;
}
Console.WriteLine($"Last Swing High: {lastSwing}");
if (Core.Instance.AccountOperations != null) return;
if (lows[0] < lows[1] && lows[1] < lows[2] && highs[0] < highs[1] && highs[1] < highs[2] && highs[2] < highs[3] && quote.Bid < lows[0])
{
double stoploss = highs[0];
double takeprofit = quote.Bid - (highs[0] - quote.Bid) * RiskRatio;
Core.Instance.PlaceOrder(new PlaceOrderRequestParameters()
{
Account = this.account,
Symbol = this.symbol,
Side = Side.Sell,
Quantity = LotSize,
StopLoss = SlTpHolder.CreateSL(stoploss, PriceMeasurement.Offset),
TakeProfit = SlTpHolder.CreateSL(takeprofit, PriceMeasurement.Offset),
OrderTypeId = OrderType.Market
});
}
else if (lows[0] > lows[1] && lows[1] > lows[2] && lows[2] > lows[3] && highs[0] > highs[1] && highs[1] > highs[2] && quote.Ask > highs[0])
{
double stoploss = lows[0];
double takeprofit = quote.Ask + (quote.Ask - lows[0]) * RiskRatio;
Core.Instance.PlaceOrder(new PlaceOrderRequestParameters()
{
Account = this.account,
Symbol = this.symbol,
Side = Side.Buy,
Quantity = LotSize,
StopLoss = SlTpHolder.CreateSL(stoploss, PriceMeasurement.Offset),
TakeProfit = SlTpHolder.CreateSL(takeprofit, PriceMeasurement.Offset),
OrderTypeId = OrderType.Market
});
}
//Console.WriteLine($"Last Swing High: {lastSwing}");
//Core.Instance.PlaceOrder(this.symbol, this.account, Side.Buy);
}
private void SymbolOnNewLast(Symbol symbol, Last last)
{
// Add your code here
}
}
}

Подробнее здесь: https://stackoverflow.com/questions/790 ... r-strategy