Any help would be appreciated.Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
% of ATR for Market Analyzer
Collapse
X
-
% of ATR for Market Analyzer
I'm just trying to create an indicator that takes X% of daily ATR over a given period. You could change the % if you want to use it for stops or profit targets. Can't seem to figure out what I'm doing wrong here... Seems like this should be pretty straightforward. Although I have no experience at this
Any help would be appreciated.
Tags: None
-
Hi tvaughan4, thanks for your note.
If you want to make the percentage modifiable from the indicators menu make it a public property e.g.
To get the value of an ATR on a particular bar, define the statement like so:Code:#region Properties [NinjaScriptProperty] [Range(1, double.MaxValue)] [Display(Name="ATRPercentage", Order=1, GroupName="Parameters")] public double ATRPercentage { get; set; } #endregion
double myvalue = ATRPercentage*ATR(20)[0]; //a 20 period ATR
What you have is a declaration, the implementation needs some integer that represents the ATR period.
Please let me know if I can assist any further.
-
So I have it compiling now. I just made the percentage and ATR value fixed for now for simplicity. But it's spitting out zero for the number (ATRProfitTarget), which is obviously incorrect. ???
namespace NinjaTrader.NinjaScript.Indicators.MyIndicators
{
public class ATRTarget : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Percent Target from Daily ATR";
Name = "ATRTarget";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
AddPlot(Brushes.Orange, "ATRProfitTarget");
}
}
protected override void OnBarUpdate()
{
double ATRProfitTarget = .25*ATR(10)[0];
}
}
}
Comment
-
Hello tvaughan4,
It looks like Chris was testing a Print statement to confirm the value where you are not outputting the value in any way. I would suggest that you also do a Print and then check the output window to confirm the value is working.
The AddPlot alone doesn't do anything except adds a plot, it doesn't look like you are setting the plot in OnBarUpdate. To set the plot you would need to use Value:
orCode:Value[0] = someValue;
Code:double ATRProfitTarget = .25*ATR(10)[0]; Value[0] = ATRProfitTarget;
Please let me know if I can assist any further.
Comment
-
Hello tvaughan4,
Generally to convert to an amount of ticks you could multiply by the tick size:
double ticks = amount * TickSize;
For example if we wanted to know the price 4 ticks away from the current price it looks like:
double price = Close - (4 * TickSize);
I look forward to being of further assistance.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
599 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
345 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
558 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
558 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment