Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error with IOrder object

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

    Error with IOrder object

    My strategy that works on calculateonbarclose=true is doing some strange thing. It duplicate orders. Then, I am trying to launch a new order only if the IOrder is not filled,

    Code:
    if(longOrder.OrderState == OrderState.Filled){}else{longOrder = EnterLong(1,"Long");}

    I can compile but when the the strategy is enabled the outputwindow launch this message:


    **NT** Error on calling 'OnBarUpdate' method for strategy

    Thank you for help

    #2
    Hello,

    Thank you for the question.

    If you would like to check if you are currently in a position to prevent logic until that position has filled, you could do that two ways.

    The first would be from OnBarUpdate by checking the Position or:

    Code:
    if(Position.CurrentMarketPosition == MarketPosition.Flat)
    {
       EnterLong();
    }


    The second would be to use OnExecution to check for the actual filled order is the order you submitted. Because you are already storing the order as a variable, OnExecution may be more beneficial depending on what you are trying to do. There is a sample in the helpguide here: http://ninjatrader.com/support/helpG...ub=onexecution

    I look forward to being of further assistance.

    Comment


      #3
      Thank you Jesse,

      The first dont work. The duplicate orders ocurrs with this code:


      Code:
      if(Position.MarketPosition.ToString() != "Long"){ 
         EnterLong(); 
      }
      Yes, CalculateonBarClose is = false

      Comment


        #4
        Hello,

        Thank you for the reply.

        What you have provided should work but generally you can just use the enum value, you could use the enum instead of a string if you check the Position object:

        if(Position.CurrentMarketPosition == MarketPosition.Flat)
        {

        }

        MarketPosition.Flat, .Long or .Short.

        If you are still seeing double orders, it could be the Entries per direction you have set, in the case the condition can become true again it would allow for another entry.

        If you can post the full context of the test you are doing it may be more apparent what the problem is.

        I look forward to being of further assistance.
        Last edited by NinjaTrader_Jesse; 06-30-2016, 09:47 AM.

        Comment


          #5
          Ok, the problem was solved.

          Ninjatrader take ExitLong() function like the same as EnterShort() ...


          Thank you

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          558 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X