/// <summary> /// Computes the next value of this indicator from the given state /// </summary> /// <param name="time"></param> /// <param name="input">The input given to the indicator</param> /// <returns> A new value for this indicator </returns> protected override DoubleArray Forward(long time, DoubleArray input) { if (!IsReady) { Current = new DoubleArrayStructScalar <TradeBarValue>(); Current.Open = (input.Open + input.Close) / 2d; Current.Close = (input.Open + input.High + input.Low + input.Close) / 4d; Current.High = input.High; Current.Low = input.Low; } else { Current.Open = (Current.Open + Current.Close) / 2d; Current.Close = (input.Open + input.High + input.Low + input.Close) / 4d; Current.High = Math.Max(input.High, Math.Max(Current.Open, Current.Close)); Current.Low = Math.Min(input.Low, Math.Min(Current.Open, Current.Close)); } return(Current.Clone()); }
/// <summary> /// Aggregates the new 'data' into the 'workingBar'. The 'workingBar' will be /// null following the event firing /// </summary> /// <param name="workingBar">The bar we're building, null if the event was just fired and we're starting a new trade bar</param> /// <param name="data">The new data</param> protected override void AggregateBar(ref long workingTime, ref DoubleArray workingBar, long time, DoubleArray data) { if (workingBar == null) { workingBar = new DoubleArrayStructScalar <TradeBarValue>(new TradeBarValue(data.Close, data.High, data.Low, data.Open, data.Volume)); workingTime = GetRoundedBarTime(time); } else { //Aggregate the working bar workingBar.Close = data.Close; workingBar.Volume += data.Volume; if (data.Low < workingBar.Low) { workingBar.Low = data.Low; } if (data.High > workingBar.High) { workingBar.High = data.High; } } }
/// <summary> /// Aggregates the new 'data' into the 'workingBar'. The 'workingBar' will be /// null following the event firing /// </summary> /// <param name="workingBar">The bar we're building, null if the event was just fired and we're starting a new consolidated bar</param> /// <param name="data">The new data</param> protected override void AggregateBar(ref long workingTime, ref DoubleArray workingBar, long time, DoubleArray data) { #if DEBUG if (data.Properties < TickValue.Properties) { throw new ArgumentException($"data was expected to be TickValue with properties>={TickValue.Properties}", nameof(data)); } #endif var value = data.Value; if (workingBar == null) { workingTime = GetRoundedBarTime(time); workingBar = new DoubleArrayStructScalar <TradeBarValue>(new TradeBarValue() { Close = value, High = value, Low = value, Open = value, Volume = data.Volume }); } else { //Aggregate the working bar workingBar.Close = value; workingBar.Volume += data.Volume; if (data.Value < workingBar.Low) { workingBar.Low = value; } if (data.Value > workingBar.High) { workingBar.High = value; } } }