In the UnmanagedOCOBracketExample_NT8 note I've used OrderType.StopMarket orders.
A buy stop order would be placed above the ask, a sell stop order would be placed below the bid.
In this code you have chosen to use OrderType.Limit which are placed on the reverse side of the market.
A buy limit would be placed below the ask, a sell limit would be placed above the bid.
I see in your code you've submitted the buy limit at the High of the most recently closed bar and the sell limit at the Low of the most recently closed bar. These orders will most likely be on the wrong side of the market when the new bar opens.
With some brokerages that order will be immediately filled (including NinjaTrader), with other brokerages that order would be rejected (such as Forex brokerages).
Also, orders should be assigned to variables in OnOrderUpdate() and not directly from the order method.
I've changed is and tested the suggested code and I am finding this is working.
Below is a link to a video of the test.
BobperezTest_NT8.zip
There are no exit orders or setting the variables back to null so it only places orders once, but this works as expected.
Comment