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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        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 r68cervera, Today, 05:29 AM
          0 responses
          2 views
          0 likes
          Last Post r68cervera  
          Started by geddyisodin, Today, 05:20 AM
          0 responses
          3 views
          0 likes
          Last Post geddyisodin  
          Started by JonesJoker, 04-22-2024, 12:23 PM
          6 responses
          33 views
          0 likes
          Last Post JonesJoker  
          Started by GussJ, 03-04-2020, 03:11 PM
          12 responses
          3,239 views
          0 likes
          Last Post Leafcutter  
          Started by AveryFlynn, Today, 04:57 AM
          0 responses
          6 views
          0 likes
          Last Post AveryFlynn  
          Working...
          X