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 algospoke, Yesterday, 06:40 PM
          2 responses
          22 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          21 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X