I'm trying to program a strategy that, on a 1-second chart, sends a buy order when the 1-second, 1-minute, and up to 300-minute bars start within the same second.
To do this, I used the following code:
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Second, 1);
AddDataSeries(Data.BarsPeriodType.Minute, 1);
AddDataSeries(Data.BarsPeriodType.Minute, 2);
AddDataSeries(Data.BarsPeriodType.Minute, 3);
AddDataSeries(Data.BarsPeriodType.Minute, 4);
.
.
.
AddDataSeries(Data.BarsPeriodType.Minute, 300);
}
protected override void OnBarUpdate()
{
if(CurrentBars[300] < 2)
{return;}
if(BarsInProgress == 0 && IsFirstTickOfBar)
{
EndBar1sec = true;
}
if(BarsInProgress == 1 && IsFirstTickOfBar)
{
EndBar1min = true;
}
.
.
.
if(BarsInProgress == 300 && IsFirstTickOfBar)
{
EndBar300min = true;
}
if(EndBar1sec && BarEnd1min)
{
if(EndBar1sec && EndBar2min)
{
.
.
.
if(EndBar1sec && EndBar300min)
{
EnterLong();
EndBar1sec = false;
EndBar1min = false;
.
.
.
EndBar300min = false;
}
EndBar2min = false;
}
EndBar1min = false;
EndBar1sec = false;
}
But I find that, when nesting the 300 If conditions, there must be a limit because they aren't being collected correctly and the program is behaving quite erratically.
Is there a limit to nesting If conditions in NinjaTrader?
If so, what alternative do I have to program the simultaneous start condition for 1 second, 1 minute, etc. Up to 300 minutes in minute intervals (1, 2, 3,..., 298, 299, and 300)?
Thanks in advance.

Comment