Hello all, this strategy is working fine in Playback, but when I try to enable it in Live it fails to enable. It compiled without errors. Yesterday the same Strategy worked in both Live and Playback
Anybody knows what the problem might be?
Thank you
Now, half hour later it’s not enables in Playback too
Should I rewrite?
Don’t rewrite yet. When a strategy fails to enable or switches itself off, NinjaTrader writes the reason to the Log tab of the Control Center. Try to enable it, then open the Log tab: the message says which method failed and usually on which bar. Post that line here if it isn’t clear.
Since the code didn’t change and it worked yesterday, my bet is the data, not the code. Every time you enable a strategy it first runs over the history loaded on the chart, and that window moves with the clock (in Playback too). So a bar that trips an error can be new today. The most common one is “Index was out of range”: reading something like Close[1] or High[10] on a bar that doesn’t have that many bars before it. The fix is a guard at the top of OnBarUpdate, if (CurrentBar < 10) return;, with 10 being the furthest bars-ago you read (and a CurrentBars[1] check too if you added a second series). The help guide covers it: Make sure you have enough bars.
One case that only looks like a failure: if it does enable but shows yellow in the Strategies tab, it’s waiting for the account to be flat. Over that history the strategy ended in a position your account doesn’t have, and with the default start behavior (Wait until flat) it holds off until the account is flat.
Brilliant!
In protected override void OnBarUpdate() I changed if (CurrentBars[0] < 2) to if (CurrentBars[0] < 3) and it enables now.
Thank you so much ScorpioEdge