Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Try to get the ATR for a daily chart

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

    Try to get the ATR for a daily chart

    I am trying to use the average true range to set my strategy stop loss and target exits. My strategy is running on a daily chart with the Calculate on price change set. When I try to get the ATR for a 5 day, 14 day, or 30 day period the values coming back are near zero. Is this because it is basing it off the ticks and not the days.

    Here is the code for the stop loss calculation.

    Code:
    private double LongStopPrice(double entryPrice)
    {
         // ATR_LB_Stop set to 5
         Series<double> averageTrueRange = new Series<double>(this);
         Indicators.ATR atr = ATR(averageTrueRange, ATR_LB_Stop);
         double stop = (StopLossMulti * atr[0]);
    
         return entryPrice - stop;
    }

    #2
    Cleaned up the code a bit but still have very small numbers coming back. This is returning ~0.005, for the ATR, is this correct?

    Code:
    private double LongStopPrice(double entryPrice)
    {
         double atr = ATR(ATR_LB_Stop)[0];
         double stop = (StopLossMulti * atr);
    
          return entryPrice - stop;
    }

    Comment


      #3
      Hello NeverDownMoney,

      Thank you for your posts.

      We would not expect to see the ATR indicator return low a value of ~0.005. You could check this by adding the ATR indicator to a chart to see the expected value.

      In your code, I see that you are instantiating an indicator in your private method. It is best practice to instantiate the indicator in OnStateChange(). You could then use AddChartIndicator() to view the indicator and its value on a chart.

      Additionally, you could add prints to print out the value of the ATR indicator and use that value along with SopLossMulti to create your stop loss

      Please review the help guide links below for more information.

      AddChartIndicator - https://ninjatrader.com/de/support/h...tindicator.htm

      ATR - https://ninjatrader.com/support/help..._range_atr.htm

      Let us know if we may further assist.
      Attached Files
      <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

      Comment


        #4
        I think that the reason that I am seeing such small numbers is that the chart instrument is 6E 12-20 (Euro December 2020), it has a very small ATR when I put it on the chart, therefore I believe it is working as expected. I put it on another cart (ES 12-20) and it seems to have much larger numbers.

        I am creating the ATR indicator in OnStateChange and saving the created value in a class private variable. Is this good coding practice?

        Code:
        else if (State == State.DataLoaded)
        {
             ATR_Target = ATR(ATR_LB_Target);
             ATR_Stop = ATR(ATR_LB_Stop);
             AddChartIndicator(ATR_Target);
        }

        Comment


          #5
          Hello NeverDownMoney,

          Thank you for that information.

          It is good coding practice to instantiate the private indicator variable before OnStateChange() followed by creating the indicator in OnStateChange() when the State reaches State.DataLoaded.

          Please see the 'Setting up resources that require market data' section of the NinjaScript Best Practices help guide page for more information - https://ninjatrader.com/support/help...urceManagement

          Let us know if we may further assist.

          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          71 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          143 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          76 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          47 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          51 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X