First I would apologize for some English mistakes.
So, I´m trying to code a Stop and Reverse ATR indicator for Ninjatrader7.
public class ATRLayout : Indicator
{
#region Variables
private int periodATR = 100;
private double percentATR = 10;
#endregion
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Dot, "UpTrend"));
Add(new Plot(Color.FromKnownColor(KnownColor.DeepPink), PlotStyle.Dot, "DownTrend"));
Overlay = true;
}
protected override void OnBarUpdate()
{
double xf = Close[0] * (1 - ((ATR(periodATR)[0] * percentATR) / 10000));
double xf1 = Close[0] * (1 + ((ATR(periodATR)[0] * percentATR) / 10000));
Lower.Set(xf);
Upper.Set(xf1);
}
#region Properties
[Browsable(false)]
[XmlIgnore()]
public DataSeries Lower
{
get { return Values[0]; }
}
public DataSeries Upper
{
get { return Values[1]; }
}
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
public int PeriodATR
{
get { return periodATR; }
set { periodATR = Math.Max(1, value); }
}
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
public double PercentATR
{
get { return percentATR; }
set { percentATR = Math.Max(1, value); }
}
After that I would improve something:
1. If (UPtrend[0] < UPtrend[1]), I would like to maintain the value of uptrend[1] until a new higher UPtrend dot appears or reverse trend if the price close below the last uptrend dot.
2. If the trend reverse, every new DOWNTrend dot needs to be lower than the last DOWNTrend dot. If the DOWNTrend dot is higher, the indicator maintains the value of the lowest dot until the trend get reverse or appears a new lower dot.
Picture in attachment with mode details.
Looking forward some ideas.
Thanks a lot.
Comment