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
      Brandon H.NinjaTrader Customer Service

      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.

          Brandon H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by soon123, Today, 02:14 AM
          0 responses
          6 views
          0 likes
          Last Post soon123
          by soon123
           
          Started by guilhem, Today, 01:53 AM
          1 response
          6 views
          0 likes
          Last Post sgkcfc
          by sgkcfc
           
          Started by elkingonzalez, 11-24-2020, 09:59 AM
          4 responses
          40 views
          0 likes
          Last Post MrSmart
          by MrSmart
           
          Started by Photon66, Today, 12:03 AM
          0 responses
          9 views
          0 likes
          Last Post Photon66  
          Started by morrnel, Yesterday, 09:38 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Marco  
          Working...
          X