public class ATRTicks : Indicator { #region Variables private int period = 14; private double scaler = 100; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(Color.Green, "ATRTicks")); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar == 0) Value.Set((High[0] - Low[0]) * 1/TickSize); else { double trueRange = (High[0] - Low[0]); trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1]))); Value.Set((((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period)) * 1/TickSize); } } #region Properties /// <summary> /// </summary> [Description("Numbers of bars used for calculations")] [GridCategory("Parameters")] public int Period { get { return period; } set { period = Math.Max(1, value); } } [Description("Scaler to take convert calculation to ticks")] [GridCategory("Parameters")] public double Scaler { get { return scaler; } set { scaler = Math.Max(1, value); } } #endregion }
Thanks
DaveN
Comment