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

  • NinjaTrader_BrandonH
    replied
    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.

    Leave a comment:


  • NeverDownMoney
    replied
    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);
    }

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    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

    Leave a comment:


  • NeverDownMoney
    replied
    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;
    }

    Leave a comment:


  • NeverDownMoney
    started a topic Try to get the ATR for a daily chart

    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;
    }

Latest Posts

Collapse

Topics Statistics Last Post
Started by RobotSyndicate, Today, 09:20 AM
0 responses
1 view
0 likes
Last Post RobotSyndicate  
Started by fx.practic, Today, 08:22 AM
2 responses
5 views
0 likes
Last Post fx.practic  
Started by brownsfan019, Today, 08:01 AM
1 response
7 views
0 likes
Last Post NinjaTrader_PatrickG  
Started by cmarkb, Today, 01:18 AM
2 responses
30 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by waldoalvarez, Today, 04:48 AM
1 response
11 views
0 likes
Last Post NinjaTrader_Jesse  
Working...
X