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
% 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.
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.Chris L.NinjaTrader Customer Service
-
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:
Code:Value[0] = someValue;
Code:double ATRProfitTarget = .25*ATR(10)[0]; Value[0] = ATRProfitTarget;
Please let me know if I can assist any further.
JesseNinjaTrader Customer Service
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.
JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
12 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
5 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
||
Started by gleichnerany, Today, 01:17 AM
|
0 responses
5 views
0 likes
|
Last Post
by gleichnerany
Today, 01:17 AM
|
||
Started by WHICKED, 03-27-2024, 12:33 PM
|
4 responses
47 views
0 likes
|
Last Post Today, 12:28 AM |
Comment