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 proptradingshop, 03-21-2024, 09:50 AM
|
5 responses
26 views
0 likes
|
Last Post Today, 05:17 AM | ||
Started by MaupinFinche, Today, 05:08 AM
|
0 responses
4 views
0 likes
|
Last Post
by MaupinFinche
Today, 05:08 AM
|
||
Started by Enkidu, Yesterday, 06:40 AM
|
9 responses
35 views
0 likes
|
Last Post
by Enkidu
Yesterday, 01:11 PM
|
||
Started by Mestor, 03-10-2023, 01:50 AM
|
12 responses
309 views
0 likes
|
Last Post
by z.franck
Today, 04:29 AM
|
||
Started by AgriTrdr, 07-16-2023, 12:54 PM
|
32 responses
269 views
0 likes
|
Last Post
by f.saeidi
Yesterday, 06:49 AM
|
Comment