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

Reset Stop Loss after Flat

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

    Reset Stop Loss after Flat

    Hello,



    The above Help Guide says

    "you should always reset the stop loss price/offset value when your strategy is flat"

    but nowhere does it say how to reset the stop loss.

    Does anyone know?

    Thanks
    Geodepe

    #2
    Call it again.

    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

    Originally posted by Geodepe View Post
    Hello,



    The above Help Guide says

    "you should always reset the stop loss price/offset value when your strategy is flat"

    but nowhere does it say how to reset the stop loss.

    Does anyone know?

    Thanks
    Geodepe

    Comment


      #3
      Is this suggesting that in my OnBarUpdate() I should have

      if (Position.MarketPosition == MarketPosition.Flat)
      SetStopLoss(defaultStopLoss); //reset

      in my strategy?

      Comment


        #4
        Originally posted by Geodepe View Post
        Is this suggesting that in my OnBarUpdate() I should have

        if (Position.MarketPosition == MarketPosition.Flat)
        SetStopLoss(defaultStopLoss); //reset

        in my strategy?
        It sounds like it.

        It should work in OnPositionUpdate ?

        Anyways, I think the issue is - if you enter a trade say at 1660.00, and you set a stop loss of 1658.00. Your stoploss or profit fires, and then you enter another trade in your strategy, the same stop loss will be initially set. So if you enter again at 1658.00, your stoploss is still 1658.00, and will probably be set off.

        That's the way I'm understanding it.

        I'm not sure if CalculationMode.Ticks would be at entry -2, or 1656.00.... I guess more clarification in the documentation is needed, and/or testing for sure.

        Comment


          #5
          Thanks for your help ... yes I think some clarification is in order.

          Comment


            #6
            Your understanding is correct - we've included the reset part in this reference sample on the topic - http://www.ninjatrader.com/support/f...ead.php?t=3222
            BertrandNinjaTrader Customer Service

            Comment


              #7
              I reviewed the linked sample and I still don't see any code showing how to clear a stop loss that was set using SetStopLoss(CalculationMode.Price, stopPx);

              Anyone?

              Comment


                #8
                Originally posted by dbooksta View Post
                I reviewed the linked sample and I still don't see any code showing how to clear a stop loss that was set using SetStopLoss(CalculationMode.Price, stopPx);

                Anyone?
                The very first lines in OnBarUpdate() are:
                Code:
                            // Resets the stop loss to the original value when all positions are closed
                            if (Position.MarketPosition == MarketPosition.Flat)
                            {
                                SetStopLoss(CalculationMode.Ticks, stoplossticks);
                            }
                IOW, you always reset the StopLoss by using CalculationMode.Ticks, as evidenced by the StopLoss adjustment uses CalculationMode.Price, thus:
                Code:
                            // If a long position is open, allow for stop loss modification to breakeven
                            else if (Position.MarketPosition == MarketPosition.Long)
                            {
                                // Once the price is greater than entry price+50 ticks, set stop loss to breakeven
                                if (Close[0] > Position.AvgPrice + 50 * TickSize)
                                {
                                    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
                                }
                            }

                Comment


                  #9
                  But this is a kludge. There must be a way to "turn off" the stop loss. So far we've just been given hacks to continually move it far enough away that it shouldn't do any damage ... although we have to remember to "reset" it in the other direction if we enter a trade in the other direction.

                  Comment


                    #10
                    Your understanding is unfortunately correct regarding the Set() methods, there's no way to cancel or unset them. For more explicit control including IOrder interface returns please check into the Exit() methods then.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by dbooksta View Post
                      But this is a kludge. There must be a way to "turn off" the stop loss. So far we've just been given hacks to continually move it far enough away that it shouldn't do any damage ... although we have to remember to "reset" it in the other direction if we enter a trade in the other direction.
                      Yes, it is something of a kludge, but it was designed to be a simple "set and forget" interface, more or less. That is also why it is best to always reset with CalculationMode.Ticks. That way you let NT take care of the direction, and need not bother whether your last trade was short or long.

                      If you want better control over your exits, use the Exit...() methods.
                      Last edited by koganam; 06-17-2014, 07:26 PM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by alifarahani, Today, 09:40 AM
                      6 responses
                      36 views
                      0 likes
                      Last Post alifarahani  
                      Started by Waxavi, Today, 02:10 AM
                      1 response
                      17 views
                      0 likes
                      Last Post NinjaTrader_LuisH  
                      Started by Kaledus, Today, 01:29 PM
                      5 responses
                      14 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by Waxavi, Today, 02:00 AM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_LuisH  
                      Started by gentlebenthebear, Today, 01:30 AM
                      3 responses
                      17 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Working...
                      X