Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Avoid strategy disabled when stoploss above the market value

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

    Avoid strategy disabled when stoploss above the market value

    Hi,

    im trying to develop a trailing stop for my strategy, using teh managed aproach (SetStopLoss) iteratively, but when the market is so volatile, apparently, when i try to put the setstoploss, in this moment the market value change its direcction so volatile and de value is below my setstoploss value.

    So, i know that is not posible to set the stoploss above the market vale (for longs) or below the market value (for shorts), but when it occurs, my strategy is disabled automatically.
    It´s possible to catch this excepcion, and does not disable my strategy and try to get the last stoploss or try to set another one? or its possible to reactivate my strategy automatically at least?

    Thank you for your help

    #2
    Hello arbeydario,

    Below is a link to a forum post on ensuring the price is a valid price.


    In a fast moving market, you would want to give a little wiggle room by increasing the distance a few ticks.

    To prevent the strategy from being disabled, use the StopCancelCloseIgnoreRejects RealtimeErrorHandling.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea, thank you for your faster answer.

      I tried to ensure the price is a valid price, it but it does not work i dont know if im doing something wrong, this is a piece of my code

      double maxValue = GetCurrentAsk();
      double mystoplossvalue = Position.AveragePrice - (newStopLossValue * TickSize);//calculates the new stoplossvalue based on the actual position value, newStopLossValue is in ticks
      if(maxValue > mystoplossvalue){
      SetStopLoss(fromEntrySignal, calculationMode, newStopLossValue, isSimulatedStop);//Calculation mode is ticks, and newStopLossValue is in ticks, the movement in ticks i want to follow the price
      }else{
      Debug("does not modify the stoploss");
      }

      besides, i tried setting the RealtimeErrorHandling = StopCancelCloseIgnoreRejects and it works and doesnot disable my strategy but has a strange behavior,
      show a lot of windows showing the error maybe 50 windows, its possible to avoid it?​


      Click image for larger version

Name:	image.png
Views:	149
Size:	53.6 KB
ID:	1317068

      Comment


        #4
        Hello arbeydario,

        It looks like the script is repeatedly submitting orders at invalid prices. Each rejected order will result in an error popup window.

        These cannot be suppressed as our users must be notified when an order is rejected so they are aware they may need to manually manage the position (or call the broker to manage the position).

        If an order is rejected, I would not recommend submitting the order again at the same price.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea, yes it seems like i repeteatedly submit orders but it is not true or at least not explicitly, it happens when i call SetStopLoss method once time.
          I put Prints when OnOrderUpdate is executed and when i call the SetStopLoss that rejects the entry, call a lot of times OnOrderUpdate showing the error Stop price can't be changed above the market. I understand that is not possible to supress the popup window but i want to saw it one time, not 100 popup windows, but i cant find why happen this...
          Let me show you the log to see if you can somehow identify the problem, i attach the log file

          Attached Files

          Comment


            #6
            Hello arbeydario,

            Set methods update the order on basically every tick.

            Use exit orders so that you can detect the order was rejected in OnOrderUpdate(), calculate a new valid price on the correct side of the market, and re-submit the order (if you want to resubmit it).
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            50 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 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