If you run the following strategy code you'll see the following completed trade on your chart.
The problem with this is that the exit happens at the MIT stop price, but should (I believe) happen at the open price.
- Submit EnterLong() on 3/12/2018
- Submit ExitLongMIT() in OnExecutionUpdate with a stop price below market.
Now, I realize this is not really a good thing to do, but it is nonetheless behavior supported by NinjaTrader and something we may find ourselves running into from time to time.
When OnExecutionUpdate runs for our entry, the market price is the open price.
As I understand, MIT orders are simulated by NinjaTrader. When the price is touched, NinjaTrader submits a market order.
Well, if that's the case, then the exit MIT order is triggered immediately and a market order is submitted.
At that moment the market price would still be the open price.
So, why doesn't the exit happen at the open instead of the MIT stop price?
Thanks,
Steve
public class MitExecutionPriceTest : Strategy { protected override void OnBarUpdate() { if (Time[0].Date == DateTime.Parse("2019-03-12").Date) { EnterLong("Tag1"); } } protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time) { if (execution.Order.Name == "Tag1") { // We submit with a MIT stop price below the open. MIT should be // triggered immediately because it's below market. Then a market // order is submitted. The market price after the entry is the // open price. But the exit still executes at the MIT stop price. // I would expect it to execute at the open, the current market // price. ExitLongMIT(2790); } } protected override void OnStateChange() { // Load ES 06-19 Day bars on the chart going back to about 3/1/2019 if (State == State.SetDefaults) { Name = "MIT Execution Price Test"; IsExitOnSessionCloseStrategy = false; Slippage = 0; TraceOrders = true; BarsRequiredToTrade = 0; } } }
Comment