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

Order error when the market gaps

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

    Order error when the market gaps

    Hello,

    I am using the following code to trigger a long order

    void Buy()
    {
    double threshold = MAX(this.High, 2)[0];
    barsLong = 0;
    base.EnterLongStopMarket(1, threshold, "VLong");

    }

    I get the following error when the market opens gap up above my threshold value

    "Buy stop or buy stop limit orders can't be placed below the market.." and then my strategy is diabled.

    The funny thing is that once I re-enable the strategy the order is submitted just fine.

    What am I doing wrong? Please advise on what to do.

    kind regards

    Ioannis



    #2
    Hello im197,

    Thanks for your post.

    Submitting the order to the maximum of the last two High values will not guarantee that when the order is submitted it will be above the current market price. You could give the order greater distance from the current market price by submitting your order to a higher price level, I. E. using something like High[0] + 10 * TickSize will submit your stop market order at a higher distance to prevent a market gap from causing a rejection of your order.

    As an alternative, you can set RealtimeErrorHandling to IgnoreAllErrors and you can trap the rejection in OnOrderUpdate. The strategy will stay running in the event of a rejection and you can have the strategy take a different action if you desire.

    RealtimeErrorHandling - https://ninjatrader.com/support/help...orhandling.htm

    OnOrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello Jim,


      I think the problem is created by the fact that I am using the ES future and regular trading hours for the strategy.

      If the previous two bars are the last bars of the day, the MAX of the previous two highs is only known when the market re-opens. If the market gaps up I am still bound to get an error message. So I have to look up the error handling part.

      I still don't understang why I don't get the same error when I re-enable the strategy. In this case the order is executed without a problem. Why does this happen?

      Kind regards

      Ioannis

      Comment


        #4
        Hello again,

        still trying to figure out how to work around the problem

        I have changed RealtimeErrorHandling and I am trying to trap the rejection, but I cant get it to work. What am I doing wrong?

        here is my code

        ----------------------------------------------

        if (State == State.SetDefaults)
        {
        RealtimeErrorHandling = RealtimeErrorHandling.StopCancelCloseIgnoreRejects ;
        }

        void Buy()
        {
        barsLong = 0;
        longEntryOrder = base.EnterLongStopMarket(1,MAX(this.High, 2)[0], "VLong");
        }

        protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled,
        double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error,
        string nativeError)
        {
        if (order.Name == "VLong" && orderState == OrderState.Rejected)
        EnterLong(1, "New VLong");
        }

        Comment


          #5
          Hello im197,

          I still don't understang why I don't get the same error when I re-enable the strategy. In this case the order is executed without a problem. Why does this happen?
          After re-enabling the strategy and the strategy calculates historical data, it will calculate that trade using historical rules instead of handling the order like it is a live order or realtime simulated order. In the historical context, the rejection will not be seen. For more information on the differences in behavior that you will see between historical and realtime data, please see the documentation below.

          Discrepancies between realtime and backtest - https://ninjatrader.com/support/help...ime_vs_bac.htm

          I have changed RealtimeErrorHandling and I am trying to trap the rejection, but I cant get it to work. What am I doing wrong?
          I have attached an example that can be used to demonstrate rejection handling. You can observe how the behavior is handled by applying the strategy to a 5 second data series.

          For a more comprehensive look at using OnOrderUpdate and Order objects, please refer to the SampleOnOrderUpdate strategy.

          SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

          If you have any questions, please don't hesitate to write back.
          Attached Files
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alifarahani, Today, 09:40 AM
          2 responses
          12 views
          0 likes
          Last Post alifarahani  
          Started by junkone, Today, 11:37 AM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by pickmyonlineclass, Today, 12:23 PM
          0 responses
          1 view
          0 likes
          Last Post pickmyonlineclass  
          Started by frankthearm, Yesterday, 09:08 AM
          12 responses
          44 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by quantismo, 04-17-2024, 05:13 PM
          5 responses
          35 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X