/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { /// ensure bar has EmProps if (props is IEmProps) { /// get EmProps for the specified bar, matching on OHLCVT EmProps barProps = props.GetEmProps(Open[0], High[0], Low[0], Close[0], (long)Volume[0], Time[0]) as EmProps; /// ensure EmProps exist for given bar (note: some historical data may not be available) if (barProps == null) { return; } /// update plots Surge.Set(barProps.Surge); Tide.Set(barProps.Tide); ErrorCount.Set(barProps.ErrorCount); ErrorVolume.Set(barProps.ErrorVolume); /// update average TideAvg.Set(EmMath.EMA((double)barProps.Tide, CurrentBar, smooth, CurrentBar == 0 ? Tide[0] : TideAvg[1])); } else { /// generate log message one time if (!invalid) { Log(String.Format("{0} does not implement interface IEmProps", Bars.BarsType.ToString()), LogLevel.Warning); invalid = true; } } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { /// ensure bar has EmProps if (props is IEmProps) { /// get EmProps for the specified bar, matching on OHLCVT EmProps barProps = props.GetEmProps(Open[0], High[0], Low[0], Close[0], (long)Volume[0], Time[0]) as EmProps; /// ensure EmProps exist for given bar (note: some historical data may not be available) if (barProps == null) { return; } /// update plots BearCount.Set(-barProps.BearCount); BearVolume.Set(-barProps.BearVolume); BullCount.Set(barProps.BullCount); BullVolume.Set(barProps.BullVolume); ErrorCount.Set(barProps.ErrorCount); ErrorVolume.Set(barProps.ErrorVolume); /// draw shading if (CurrentBar > 0) { DrawRegion("EmVolume_Bull_" + CurrentBar.ToString(), 1, 0, BullVolume, BullCount, Color.Transparent, BullColor, BullOpacity); DrawRegion("EmVolume_Bear_" + CurrentBar.ToString(), 1, 0, BearVolume, BearCount, Color.Transparent, BearColor, BearOpacity); DrawRegion("EmVolume_Zero_" + CurrentBar.ToString(), 1, 0, BullCount, BearCount, Color.Transparent, ErrorColor, ErrorOpacity); } } else { /// generate log message one time if (!invalid) { Log(String.Format("{0} does not implement interface IEmProps", Bars.BarsType.ToString()), LogLevel.Warning); invalid = true; } } }
void RemovePlots() { /// get EmProps for the previous bar EmProps barProps = props.GetEmProps(Open[1], High[1], Low[1], Close[1], (long)Volume[1], Time[1]) as EmProps; /// ensure EmProps exist for given bar (note: some historical data may not be available) if (barProps == null) { return; } /// remove successful bear line if (barProps.Close == barProps.BearClose) { RemoveDrawObject("ebtClosePlotsBear_" + (CurrentBar - 1).ToString()); } /// remove successful bull line if (barProps.Close == barProps.BullClose) { RemoveDrawObject("ebtClosePlotsBull_" + (CurrentBar - 1).ToString()); } }
void DrawPlots() { /// get EmProps for the specified bar, matching on OHLCVT EmProps barProps = props.GetEmProps(Open[0], High[0], Low[0], Close[0], (long)Volume[0], Time[0]) as EmProps; /// ensure EmProps exist for given bar (note: some historical data may not be available) if (barProps == null) { return; } /// update barId so this only fires once per bar barId = CurrentBar; /// local variables double bear = barProps.BearClose; double bull = barProps.BullClose; double close = barProps.Close; /// draw bear close if (close != bear) { DrawLine("ebtClosePlotsBear_" + CurrentBar, true, 0, bear, -1, bear, bearColor, DashStyle.Dash, 2); } /// draw bull close if (close != bull) { DrawLine("ebtClosePlotsBull_" + CurrentBar, true, 0, bull, -1, bull, bullColor, DashStyle.Dash, 2); } /// add debug to output window if (showDebug) { Print(string.Format("Bar {0} => {1}", CurrentBar, barProps)); } }
/// <summary> /// Add EmProps for bar to List /// </summary> void AddEmProps(double open, double high, double low, double close, long volume, DateTime time, int bias, double bear, double bull) { barProps = new EmProps(open, high, low, close, volume, time, bias, bear, bull); propList.Add(barProps); }
/// constructors public EmBars() : base(PeriodType.Custom7) { barProps = null; propList = new List <EmProps>(); }