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!
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
NinjaTrader
Try to get the ATR for a daily chart
Collapse
X
-
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.
-
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:
-
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:
-
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:
-
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 bortz, 11-06-2023, 08:04 AM
|
47 responses
1,611 views
0 likes
|
Last Post
by aligator
Today, 07:22 PM
|
||
Started by jaybedreamin, Today, 05:56 PM
|
0 responses
9 views
0 likes
|
Last Post
by jaybedreamin
Today, 05:56 PM
|
||
Started by DJ888, 04-16-2024, 06:09 PM
|
6 responses
19 views
0 likes
|
Last Post
by DJ888
Today, 05:12 PM
|
||
Started by Jon17, Today, 04:33 PM
|
0 responses
6 views
0 likes
|
Last Post
by Jon17
Today, 04:33 PM
|
||
Started by Javierw.ok, Today, 04:12 PM
|
0 responses
22 views
0 likes
|
Last Post
by Javierw.ok
Today, 04:12 PM
|
Leave a comment: