ATR in Tick - shows ATR in the number of ticks
public class ATRTick : Indicator
{
#region Variables
private int period = 14;
#endregion
protected override void Initialize()
{
Add(new Plot(Color.Green, "ATRTick"));
}
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
Value.Set((High[0] - Low[0]) / TickSize);
else
{
double trueRange = (High[0] - Low[0]) / TickSize;
trueRange = Math.Max(Math.Abs((Low[0] - Close[1]) / TickSize), Math.Max(trueRange, Math.Abs((High[0] - Close[1]) / TickSize)));
Value.Set((((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period)) );
}
}
#region Properties
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
#endregion
}
{
#region Variables
private int period = 14;
#endregion
protected override void Initialize()
{
Add(new Plot(Color.Green, "ATRTick"));
}
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
Value.Set((High[0] - Low[0]) / TickSize);
else
{
double trueRange = (High[0] - Low[0]) / TickSize;
trueRange = Math.Max(Math.Abs((Low[0] - Close[1]) / TickSize), Math.Max(trueRange, Math.Abs((High[0] - Close[1]) / TickSize)));
Value.Set((((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period)) );
}
}
#region Properties
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
#endregion
}
Comments
Post a Comment