Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

MIT Execution Price in Historical Order Processing

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MIT Execution Price in Historical Order Processing

    The MIT execution price in the following example is not what I would expect. This is either a bug in the historical order processing or I'm confused why it does this.

    If you run the following strategy code you'll see the following completed trade on your chart.

    Click image for larger version  Name:	2019-07-16_22-32-36.png Views:	1 Size:	14.5 KB ID:	1064273

    The problem with this is that the exit happens at the MIT stop price, but should (I believe) happen at the open price.
    1. Submit EnterLong() on 3/12/2018
    2. 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

    Code:
    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;
            }
    
        }
    }
    Last edited by Steve L; 07-16-2019, 09:57 PM.
    Steve L
    NinjaTrader Ecosystem Vendor - Ninja Mastery

    #2
    OK. I thought I understood how MIT orders work, but I'm pretty sure now that I don't.

    Are MIT orders triggered exactly like limit orders? Except with the only difference being that once the MIT is triggered it executes as a market order?

    Are MIT orders triggered when the price is actually TOUCHED or when the price threshold is exceeded? In the above example, we submit ExitLongMIT with a price of 2790. Is the MIT order triggered and executed the second it's submitted because the MIT price is exceeded? OR is the ExitLongMIT submitted and then only when the price reaches 2790 does it execute?
    Last edited by Steve L; 07-27-2019, 05:58 PM.
    Steve L
    NinjaTrader Ecosystem Vendor - Ninja Mastery

    Comment


      #3
      Hello Steve L,

      MIT orders are like stop market orders but are simulated and yes submit a market order once touched.

      I have a test script that tests updating these dynamically.
      https://ninjatrader.com/support/foru...79#post1055079

      With the order being submitted in OnExecutionUpdate() this would occur before the submission bar closes (so would not be at the open of the next bar) and would be intra-bar but likely without intra-bar data.

      I would recommend intra-bar granularity for this kind of intra-bar actions.
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by PaulMohn, Today, 03:49 AM
      0 responses
      3 views
      0 likes
      Last Post PaulMohn  
      Started by inanazsocial, Today, 01:15 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by rocketman7, Today, 02:12 AM
      0 responses
      10 views
      0 likes
      Last Post rocketman7  
      Started by dustydbayer, Today, 01:59 AM
      0 responses
      2 views
      0 likes
      Last Post dustydbayer  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      5 responses
      23 views
      0 likes
      Last Post trilliantrader  
      Working...
      X