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 frslvr, 04-11-2024, 07:26 AM
        9 responses
        123 views
        1 like
        Last Post caryc123  
        Started by rocketman7, Today, 09:41 AM
        4 responses
        15 views
        0 likes
        Last Post rocketman7  
        Started by selu72, Today, 02:01 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by WHICKED, Today, 02:02 PM
        2 responses
        16 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by f.saeidi, Today, 12:14 PM
        8 responses
        21 views
        0 likes
        Last Post f.saeidi  
        Working...
        X