Announcement

Collapse
No announcement yet.

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 NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          58 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          133 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X