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

StopLoss + Profit Target from ATR Value * a multiple Variable

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

    StopLoss + Profit Target from ATR Value * a multiple Variable

    I am trying to create a strategy where the Stop Loss and Profit Target is adjusted each trade based on the current ATR value. I know how to link the ATR into the Strategy, but if I rely on Builder it places it in with the execution section, and does not update the variable. If I try add into the Variable it gives me errors. Someone Kindly Please point me in the right direction. Understand also in addition, the ATR value would need to be computed with a Variable, such as 10 as 2.5/ .25 for quarter ticks for Profit Target. For example, if the ATR value is 4.11, Then the value would be 4.11 times 10 + 41.10 for profit. Now being this is a double number the Profit Target Varible should be set to currency.


    Thanks
    John

    #2
    I would like to add I am attempting for it update the values on each onBarUpdate.

    Comment


      #3
      Hello JLSwin,

      With the Strategy Builder, the stop loss and profit targets will not be updated dynamically. They are set once before the script starts and are not called again.
      Also, the Strategy Builder would not be capable of math that would be required for this.
      The script will need to be unlocked and coded by hand.

      In an unlocked script, you would be able to call SetStopLoss() in OnBarUpdate and update this dynamically.

      For example:

      double profitTargetPrice = Close[0] + (ATR(14)[0] * 10);
      SetProfitTarget(CalculationMode.Price, profitTargetPrice);
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thanks Chelsea B.,
        Should it be in the first region after OnBarUpdate or does it matter? My problem was where to place inside the code.

        Thanks
        John

        Comment


          #5
          Hello John,

          Actions that take place as a bar is updating (using data) should be placed in OnBarUpdate().

          Below I am providing a link to a forum post with helpful information about getting started with NinjaScript.
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by BIOK.NT, Yesterday, 01:56 PM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by betsuni_123, Yesterday, 04:20 PM
          1 response
          18 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by actualfacts.2021, 07-25-2021, 03:11 PM
          9 responses
          1,194 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by NinjaTrader_ChelseaB, 03-14-2017, 10:17 AM
          228 responses
          34,325 views
          7 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Philippe56140, 04-27-2024, 02:35 PM
          8 responses
          67 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Working...
          X