Мне нужно торговать на прорыве зигзага после выполнения некоторых условий, как на скриншоте...
Это код, который я написал:
Код: Выделить всё
using System;
using System.Collections.Generic;
using TradingPlatform.BusinessLayer;
namespace ZigZag_BREAKOUT
{
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";
}
protected override void OnCreated()
{
}
[InputParameter("LotSize")]
public double LotSize = 1;
[InputParameter("RiskRatio")]
public int RiskRatio = 1;
[InputParameter("Deviation")]
public double deviation = 2.0;
Indicator zigzag;
protected override void OnRun()
{
if (symbol == null || account == null || symbol.ConnectionId != account.ConnectionId)
{
Log("Incorrect input parameters... Symbol or Account are not specified or they have diffent connectionID.", StrategyLoggingLevel.Error);
return;
}
this.symbol = Core.GetSymbol(this.symbol?.CreateInfo());
if (this.symbol != null)
{
this.symbol.NewQuote += SymbolOnNewQuote;
this.symbol.NewLast += SymbolOnNewLast;
}
// Add your code here
zigzag = Core.Indicators.BuiltIn.ZZ(deviation);
}
protected override void OnStop()
{
if (this.symbol != null)
{
this.symbol.NewQuote -= SymbolOnNewQuote;
this.symbol.NewLast -= SymbolOnNewLast;
}
}
protected override void OnRemove()
{
this.symbol = null;
this.account = null;
// Add your code here
}
protected override List OnGetMetrics()
{
List result = base.OnGetMetrics();
return result;
}
double[] highs = { 0, 0, 0, 0 };
double[] lows = { 0, 0, 0, 0 };
private void SymbolOnNewQuote(Symbol symbol, Quote quote)
{
zigzag.AddIndicator(zigzag);
double lastSwing = zigzag.GetValue(0, 0);
double beforeLastSwing = zigzag.GetValue(0, 1);
if (lastSwing > 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
});
}
}
private void SymbolOnNewLast(Symbol symbol, Last last)
{
}
}
}

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