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

Errors when using Managed Order logic

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

    Errors when using Managed Order logic

    Hello All,

    I am using logic from the managed order side of NT8 and getting errors on rare occasion.

    My logic is attached: I am entering with two 1 lots, assigning a stop to each, and assigning a target to one. There is downstream logic for getting out of the remaining order, and I update the stop on the one order that doesn't have a target, when the first target is hit.

    I have attached the basic logic for entrance (or reversal) and also a screenshot of the error. Given the inconsistent frequency of the error, I don't think it's my logic. I'm guessing there's some race condition happening here that's causing the price of a pre-existing stop to be changed before deleted and before the new stops are placed once the reversal of position occurs. But just a guess.

    Can someone please explain these error messages and recommend a logic improvement? I need proper reversals (and target/stops to be pushed) properly 100% of the time. If I need to make a logic change that generates some kind of slight latency, that's less important than error free code.

    Thank you!!!

    -Tim





    Attached Files

    #2
    Hello ozziyhtomit,

    Thank you for the post.

    This error is generally correct in the sense that the order was invalid and cannot be placed below market. This could be that the prices you used are too close in a fast moving market but in this case it may be that you are calling the Set methods after the entry. Those should be moved to before the entry to make sure the new value is used right away and a previous orders value is not used instead.

    I would suggest to try first moving the Set methods before the entry and re test. If that does not resolve it, try a slightly larger offset for the targets to see if it happens less frequently. If you move it father away and it stops happening that would indicate the price used is too close.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      "I would suggest to try first moving the Set methods before the entry and re test."

      -> I will try this, but:

      If they are set before the entry, how will the tick based method calculate where to put targets and stops if there's no fill px yet?

      Thx

      Comment


        #4
        PS it's not that the prices I chose are too close to the market and the market is moving before the stops get to the exchange. I've been watching . . .

        Comment


          #5
          Hello ozziyhtomit,

          If they are set before the entry, how will the tick based method calculate where to put targets and stops if there's no fill px yet?
          The stops are triggered based on the order fill, if you have an order fill before the stop logic was set it would just use the last stops price and not what you set this time around. Its important to set the price before you submit the entry for it to work right. This is mentioned in the help guide however as it is written it would be hard to match it with this situation:

          Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position
          What that equates to is "call this method before your entry or when you are still flat." Any time you use a Set method you want to "prime" it before you submit the corresponding entry or order that's associated by its signal name.


          PS it's not that the prices I chose are too close to the market and the market is moving before the stops get to the exchange. I've been watching . . .
          Right but if the offset you choose makes a price that's not valid when the stop submits you would still see this when the order is submitted at a price below market. There are situations where being too close to the current market is not going to work. if you are always hitting this error based on the offsets being used you can technically still do that but it would require you to handle rejections and add logic for those cases where the order was too close and was rejected.




          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Yes this all makes perfect sense. Yes I read that snippet from the help materials:

            "Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price / offset value when your strategy is flat ..."

            but it confused me at the time. Now that you explain that 'reset the stop' means simply to call the method when flat, it is understandable.

            OK let's see if this works, and thank you again
            Last edited by ozziyhtomit; 10-28-2020, 02:35 PM.

            Comment


              #7
              Hi there,

              After making the change you proposed, I am still getting the error in the part of the code that allows for reversals.

              "What that equates to is "call this method before your entry or when you are still flat." Any time you use a Set method you want to "prime" it before you submit the corresponding entry or order that's associated by its signal name."

              I have done this and I am still seeing problems.

              1. Now that I call the methods before EnterLong and EnterShort, is the only remaining possible explanation that the market has moved too fast? Or, could it be something else?

              So my next change is to call the relevant methods in OnPositionUpdate, iff quantity == 0.

              SetProfitTarget
              SetStopLoss

              2. Do you think that will help? What else would you propose?

              Thanks again,
              Tim

              Comment


                #8
                Hello ozziyhtomit,

                1. Now that I call the methods before EnterLong and EnterShort, is the only remaining possible explanation that the market has moved too fast? Or, could it be something else?
                Yes that is very likely the case if you are using very tight offsets. Not all offsets will be valid depending on the active market and how close/timing of the submission.



                2. Do you think that will help? What else would you propose?
                That wouldn't be necessary for the help guide comment, calling the methods before the entry in your code would be what is suggested. If you wanted to wait for the entry to be filled and then later calculate a price you could use it for that purpose to submit orders later after the entry filled and the position is updated.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by algospoke, Yesterday, 06:40 PM
                2 responses
                18 views
                0 likes
                Last Post algospoke  
                Started by ghoul, Today, 06:02 PM
                3 responses
                14 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                44 views
                0 likes
                Last Post jeronymite  
                Started by Barry Milan, Yesterday, 10:35 PM
                7 responses
                20 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by AttiM, 02-14-2024, 05:20 PM
                10 responses
                180 views
                0 likes
                Last Post jeronymite  
                Working...
                X