Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Stops when price too volatile

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

    Strategy Stops when price too volatile

    I want to add error handling, or some mechanism to prevent NT from cancelling the strategy when price moves too quickly beyond order placement position.

    For example my strategy places an order to go long one tick above a bull bar. If price moves too fast after bar closes (thin market), before NT has a chance to add the order using EnterLongStopMarket(), NT will generate an error when it tries to then place the order.

    How can I add error handling to prevent the strategy from just stopping. I just want to cancel that order, and let the strategy continue.

    Thanks.




    #2
    Hello globaljobber,

    While you can add handling for that it would also require adding handling for any other potential error you may encounter which opens the script up to a lot of problems. Generally we suggest increasing the offset to avoid having the strategy place invalid priced orders.

    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    Comment


      #3
      Hello there,

      I don't want to change the strategy entry criteria at this point.

      The only error I get is the one here. Otherwise the strategy so far runs well.

      Can I not just add error handling for this one issue?

      I would really like to add error handling to catch this error so that it avoids NT stopping the strategy.


      Many thanks
      Gerard

      Comment


        #4
        Hello globaljobber,

        When you change the error handling setting that means you will handle all rejections in code and not just that one. If you feel comfortable doing that you can change the setting to avoid rejections. The better solution is to correct the pricing used for the order so it does not get placed on the wrong side of the market. Volatile markets are a normal part of trading so in some cases you cannot use prices that are close to market because the rate of rejection increases.

        Comment


          #5
          You could put the entry condition in a try { block and print the exception when the trade isn't taken due to volatility.

          Comment


            #6
            That's a fair point. I'll go and do some more consideration!

            Comment


              #7
              Hello wisdomspoon,

              Putting an entry condition in a try block won't avoid rejections and it will still disable the strategy upon rejection. Try in C# is only to try code that can raise an exception, order methods do not raise exceptions because the rejection is handled on a different thread for the execution. The best solution is still increasing the offset, if you need to you can handle rejections as well.

              Comment


                #8
                Rejections are a part of my life :0)

                Thanks for your help Jesse.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                44 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                124 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                65 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X