I would like to include a filter condition in my strategy = (if last 3 trades wins, not enter in the next trade).
But i cannot solve an index out of bounds array error
public class longstrategy : Strategy
{
double firstTradeProfitCurrency = 0;
double secondTradeProfitCurrency = 0;
double thirdTradeProfitCurrency =0;
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
// if (CurrentBar < BarsRequiredToTrade)
// return;
if(CurrentBars[0] < 10 || CurrentBars[1] < 10 || CurrentBars[2] < 10 || CurrentBars[3] < 10) return;
// Evaluate strategy logic once per bar
if (IsFirstTickOfBar)
{
firstTradeProfitCurrency = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1].ProfitCurrency;
secondTradeProfitCurrency = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 2].ProfitCurrency;
thirdTradeProfitCurrency = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 3].ProfitCurrency;
if ((firstTradeProfitCurrency<=0) || (secondTradeProfitCurrency<=0) || (thirdTradeProfitCurrency<=0))
enter long
...
...
...
thanks in advance

Comment