I first tried using the built-in Exit On Close functionality, but after much back and forth with support, it was suggested I don't use this means to exit end of day.
So, I employed this:
// exit EOD
if(ToTime(Time[0])>=eodExitTime)
{
ExitShort();
}
But, as soon as I tested it, I realized there would be a problem because I run Range bars of various sizes. This means that, given a range bar of just the right size, the time spanned from bar start to bar end would contain my eodExitTime. In turn, that means that when loading the strategy, the historical bars would still cause a Strategy Position to exist at end of day (becuase on historical data the strategy doesn't calculate until end of bar and there is no next bar's first tick to trigger the onBarUpdate), which then screws up the ability to properly enter at the start of the next day.
So then, I thought, aha! Let's just put in If(Historical)return;
But, alas, that doesn't work either, because according to Ninja documentation, Historical will return True until the virtual position is flat.
So, how can I effect and EOD exit that consistently works using Range bars?

Comment