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

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 bortz, 11-06-2023, 08:04 AM
        47 responses
        1,606 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        13 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X