Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question on resetting a stopLoss value

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

    Question on resetting a stopLoss value

    In help, I have read:


    "· It is suggested to call this method from within the strategy Initialize() method if your stop loss price/offset is static

    · You may call this method from within the strategy OnBarUpdate() method should you wish to dynamically change the stop loss price while in an open position

    · 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."



    I am calculating a value that will need to be reset as the market moves.

    My code currently looks like this:

    SetProfitTarget("SellShort", CalculationMode.Price, (Position.AvgPrice - shortProfit));

    SetStopLoss("SellShort", CalculationMode.Price, (Position.AvgPrice + shortStopLoss), false);


    How do reset said value as mentioned above so that when I flatten i can begin the process completely anew...?

    Thanks in advance,

    Andrew

    #2
    Andrew,

    You could use something like :

    if ( Position.MarketPosition == MarketPosition.Flat )
    {

    SetProfitTarget("SellShort", CalculationMode.Price, Default1);

    SetStopLoss("SellShort", CalculationMode.Price, Default2 , false);

    }
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Ty Adam,

      the obvious question emerges:

      Why does setting something to default1 or 2 help my process, and how do I define these values? Isn't that no better than leaving them alone...or is the process actually there to create a condition of "flat" which then becomes false upon new entry?

      ...so i could make double default1 equal to "1,000,000,000,000"

      and double default 2 equal to "0.00003"...?

      Do I have this right?

      Thanks and regards.

      Comment


        #4
        alabell,

        The default1 and default2 were just place-holders. You can set these fields to whatever you want. Essentially, the idea is to reset your stop loss and take profit to a default value that you can either setup as a variable or just put it directly where default1 or default2 sit.
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sjsj2732, Yesterday, 04:31 AM
        0 responses
        31 views
        0 likes
        Last Post sjsj2732  
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        286 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        283 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        132 views
        1 like
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        91 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Working...
        X