Stop Orders Getting Rejected Pain

This is a painful spot for NinjaTrader and I have already written quite a few blog posts on this but just recently I came across a quick walking stick that I would like to share.

Basically to outline a problem imagine two bars. You get filled on one bar lets say at 15:00, next bar is 15:05 and previous bar is 14:55. So you get filled whilst the 14:55 - 15:00 bar is forming, so a bar with 15:00 close time.

Now we are only talking about a historical back test here. So when we get filled, we place a stop inside the OnExecutionUpdate method/event that NinjaTrader calls when an order gets filled. That is a quite logical thing to do especially if you don't want to write 2 different code bases for your historical back test system and your live strategy.

So what can possibly go wrong in this wonderful and though through scenario? Well, the 15:00 bar close can have a low that hits your stop that you set whilst it was forming and NinjaTrader will reject your order after which everything will go "south".

Well how about checking the low of the bar before placing the stop and if Low[0] is lower or equal to or stop move the stop. Well apart from the fact that this kind of spoils our logic there is one more little thing you need to have in mind.

When you call Low[0] inside OnExecutionUpdate you won't get the low of the entry bar you will get the low of the previous bar so the 14:55 bar. Amazing!!!! Just in time!)))

So here is the "walking stick"!

var lowAhead = BarsArray[0].GetLow(CurrentBar + 1);

This will return the low of the future bar! 

Enjoy!)