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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X