/// <summary> /// </summary> /// <param name="bars"></param> /// <param name="open"></param> /// <param name="high"></param> /// <param name="low"></param> /// <param name="close"></param> /// <param name="time"></param> /// <param name="volume"></param> /// <param name="isRealtime"></param> public override void Add(Data.Bars bars, double open, double high, double low, double close, DateTime time, int volume, bool isRealtime) { if (bars.Count == 0) { AddBar(bars, open, high, low, close, time, volume); } else { UpdateBar(bars, open, high, low, close, time, volume); Data.Bar bar = (Bar)bars.Get(bars.Count - 1); double tall = 1 + ((bar.High - bar.Low) / bars.Instrument.MasterInstrument.TickSize); double denom = tall; if (tall > 10) { denom -= ((tall - 10) / 2.0); } if (tall > 20) { denom -= ((tall - 20) / 3.0); } if ((bar.Volume / denom) >= ((double)(bars.Period.Value))) { AddBar(bars, close, close, close, close, time, 0); } } }
private bool RangeExceeded(Data.Bars bars, double price) { int cmpHi = bars.Instrument.MasterInstrument.Compare(price, renkoHigh); int cmpLo = bars.Instrument.MasterInstrument.Compare(price, renkoLow); return(cmpHi > 0 || cmpLo < 0); }
public rwt.ExtendedData getExtraData(int barsBack, Data.Bars bars, int cb) { var idx = extdat.Count - bars.Count + cb - barsBack; if (idx < 0) { return(null); } return(extdat[idx]); }
private DateTime GetLastBarSessionDate(DateTime time, Data.Bars bars, PivotRange pivotRange) { if (time > cacheSessionEnd) { if (Bars.BarsType.IsIntraday) { Bars.Session.GetNextBeginEnd(time, out cacheSessionBegin, out cacheSessionEnd); sessionDateTmp = System.TimeZoneInfo.ConvertTime(cacheSessionEnd.AddSeconds(-1), System.TimeZoneInfo.Local, Bars.Session.TimeZoneInfo).Date; } else { sessionDateTmp = time.Date; } } if (pivotRange == PivotRange.Daily) { if (sessionDateTmp != cacheSessionDate) { if (newSessionBarIdxArr.Count == 0 || (newSessionBarIdxArr.Count > 0 && CurrentBar > (int)newSessionBarIdxArr[newSessionBarIdxArr.Count - 1])) { newSessionBarIdxArr.Add(CurrentBar); } cacheSessionDate = sessionDateTmp; } return(sessionDateTmp); } else if (pivotRange == PivotRange.Weekly) { DateTime tmpWeeklyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Weekly); if (tmpWeeklyEndDate != cacheWeeklyEndDate) { if (newSessionBarIdxArr.Count == 0 || (newSessionBarIdxArr.Count > 0 && CurrentBar > (int)newSessionBarIdxArr[newSessionBarIdxArr.Count - 1])) { newSessionBarIdxArr.Add(CurrentBar); } cacheWeeklyEndDate = tmpWeeklyEndDate; } return(tmpWeeklyEndDate); } else // pivotRange == PivotRange.Monthly { DateTime tmpMonthlyEndDate = RoundUpTimeToPeriodTime(sessionDateTmp, PivotRange.Monthly); if (tmpMonthlyEndDate != cacheMonthlyEndDate) { if (newSessionBarIdxArr.Count == 0 || (newSessionBarIdxArr.Count > 0 && CurrentBar > (int)newSessionBarIdxArr[newSessionBarIdxArr.Count - 1])) { newSessionBarIdxArr.Add(CurrentBar); } cacheMonthlyEndDate = tmpMonthlyEndDate; } return(tmpMonthlyEndDate); } }
/// <summary> /// </summary> /// <param name="bars"></param> /// <param name="open"></param> /// <param name="high"></param> /// <param name="low"></param> /// <param name="close"></param> /// <param name="time"></param> /// <param name="volume"></param> /// <param name="isRealtime"></param> public override void Add(Data.Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isRealtime) { if ((curdat == null) || (time < curdat.dt)) { extdat.Clear(); extdat.TrimExcess(); curdat = null; tickSize = bars.Instrument.MasterInstrument.TickSize; } if (bars.Count == 0) { while (volume > 0) { AddBar(bars, open, high, low, close, time, Math.Min(bars.Period.Value, volume), isRealtime); RWTAddExtDat(time, close, Math.Min(bars.Period.Value, volume)); volume -= bars.Period.Value; } } else { long volTemp = 0; if (!bars.IsNewSession(time, isRealtime)) { volTemp = Math.Min(bars.Period.Value - bars.GetVolume(bars.Count - 1), volume); if (volTemp > 0) { UpdateBar(bars, open, high, low, close, time, volTemp, isRealtime); if (curdat == null) { RWTAddExtDat(time, close, 0); } else { curdat.dt = time; } RWTUpdateCounts(close); RWTUpdateCurdat(close, volTemp); } } volTemp = volume - volTemp; while (volTemp > 0) { AddBar(bars, open, high, low, close, time, Math.Min(bars.Period.Value, volTemp), isRealtime); RWTAddExtDat(time, close, Math.Min(bars.Period.Value, volTemp)); volTemp -= bars.Period.Value; } } prevClose = close; }
private void CheckBarComplete(Data.Bars bars, double price, double brickSize) { int cmpHi = bars.Instrument.MasterInstrument.Compare(price, renkoHigh); int cmpLo = bars.Instrument.MasterInstrument.Compare(price, renkoLow); if (cmpHi == 0 || cmpLo == 0) { barState = State.BarComplete; MoveLimits(bars, price, brickSize); // will move limits once since equal } else { barState = State.BarAccumulating; } }
/// <summary> /// </summary> /// <param name="chartControl"></param> /// <param name="graphics"></param> /// <param name="bars"></param> /// <param name="panelIdx"></param> /// <param name="fromIdx"></param> /// <param name="toIdx"></param> /// <param name="bounds"></param> /// <param name="max"></param> /// <param name="min"></param> public override void PaintBars(ChartControl chartControl, Graphics graphics, Data.Bars bars, int panelIdx, int fromIdx, int toIdx, Rectangle bounds, double max, double min) { if (fromIdx >= toIdx) // DrawLines needs at least 2 elements to draw line { return; } System.Collections.ArrayList points = new System.Collections.ArrayList(); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(bounds, UpColor, DownColor, System.Drawing.Drawing2D.LinearGradientMode.Vertical); if (fromIdx > 0) { fromIdx--; } if (toIdx < bars.Count - 1) { toIdx++; } for (int idx = fromIdx; idx <= toIdx; idx++) { int x = chartControl.GetXByBarIdx(bars, idx); Point point = new Point(x, chartControl.GetYByValue(bars, bars.GetClose(idx))); points.Add(point); } if (points.Count == 0) { return; } System.Drawing.Drawing2D.SmoothingMode oldSmoothingMode = graphics.SmoothingMode; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; graphics.DrawLines(Pen, (Point[])points.ToArray(typeof(Point))); points.Add(new Point(chartControl.GetXByBarIdx(bars, toIdx), bounds.Bottom)); points.Add(new Point(chartControl.GetXByBarIdx(bars, fromIdx), bounds.Bottom)); graphics.FillPolygon(brush, (Point[])points.ToArray(typeof(Point))); graphics.SmoothingMode = oldSmoothingMode; }
/// <summary> /// </summary> /// <param name="bars"></param> /// <param name="open"></param> /// <param name="high"></param> /// <param name="low"></param> /// <param name="close"></param> /// <param name="time"></param> /// <param name="volume"></param> /// <param name="isRealtime"></param> public override void Add(Data.Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isRealtime) { if ((curdat == null) || (time < curdat.dt)) { extdat.Clear(); extdat.TrimExcess(); curdat = null; tickSize = bars.Instrument.MasterInstrument.TickSize; } if (bars.Count == 0) { while (volume > 0) { AddBar(bars, open, high, low, close, time, Math.Min(volume, bars.Period.Value), isRealtime); RWTAddExtDat(time, close, Math.Min(bars.Period.Value, volume)); volume -= bars.Period.Value; } } else { if (!bars.IsNewSession(time, isRealtime)) { if (curdat == null) { RWTAddExtDat(time, close, 0); } else { curdat.dt = time; } UpdateBar(bars, open, high, low, close, time, volume, isRealtime); RWTUpdateCounts(close); RWTUpdateCurdat(close, volume); volume = 0; } while ((volume > 0) || (Math.Abs(curdat.dClose - curdat.dOpen) >= bars.Period.Value)) { AddBar(bars, close, close, close, close, time, volume, isRealtime); RWTAddExtDat(time, close, volume); volume = 0; } } prevClose = close; }
private void MoveLimits(Data.Bars bars, double price, double brickSize) { if (bars.Instrument.MasterInstrument.Compare(price, renkoHigh) >= 0) { do { renkoHigh += brickSize; renkoLow = renkoHigh - 3.0 * brickSize; } while (bars.Instrument.MasterInstrument.Compare(price, renkoHigh) > 0); // stops if price in range, including edge } else { do { renkoLow -= brickSize; renkoHigh = renkoLow + 3.0 * brickSize; } while (bars.Instrument.MasterInstrument.Compare(price, renkoLow) < 0); } }
/// <summary> /// </summary> /// <param name="bars"></param> /// <param name="open"></param> /// <param name="high"></param> /// <param name="low"></param> /// <param name="close"></param> /// <param name="time"></param> /// <param name="volume"></param> /// <param name="isRealtime"></param> public override void Add(Data.Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isRealtime) { if ((curdat == null) || (time < curdat.dt)) { extdat.Clear(); extdat.TrimExcess(); curdat = null; tickSize = bars.Instrument.MasterInstrument.TickSize; tlb = time; } if (bars.Count == 0) { RWTAddExtDat(time, close, volume); tlb = TimeToBarTime(bars, time, bars.Session.NextBeginTime, bars.Period.Value, isRealtime); AddBar(bars, open, high, low, close, time, volume, isRealtime); } else { if (curdat == null) { RWTAddExtDat(time, close, 0); } curdat.dt = time; if (time < tlb) { UpdateBar(bars, open, high, low, close, time, volume, isRealtime); RWTUpdateCounts(close); RWTUpdateCurdat(close, volume); } else { Bar bar = (Bar)bars.Get(bars.Count - 1); UpdateBar(bars, bar.Open, bar.High, bar.Low, bar.Close, tlb, 0, isRealtime); curdat.dt = tlb; RWTAddExtDat(time, close, volume); tlb = TimeToBarTime(bars, time, bars.Session.NextBeginTime, bars.Period.Value, isRealtime); AddBar(bars, open, high, low, close, time, volume, isRealtime); } } prevClose = close; }
/// <summary> /// </summary> public override double GetPercentComplete(Data.Bars bars, DateTime now) { throw new ApplicationException("GetPercentComplete not supported in " + DisplayName); }
public override void Add(Data.Bars bars, double open, double high, double low, double close, DateTime time, int volume, bool isRealtime) #endif { double brickSize = bars.Instrument.MasterInstrument.Round2TickSize(bars.Period.Value * bars.Instrument.MasterInstrument.TickSize); // #ticks per brick * tickSize // starting new bar at session boundary makes sure you have the same bars // reguadless of the first date that is loaded in the chart, feel free to remove #if NT7 if ((bars.Count == 0) || bars.IsNewSession(time)) #else if (bars.Count == 0) #endif { #if NT7 AddBar(bars, close, close, close, close, time, volume, isRealtime); #else AddBar(bars, close, close, close, close, time, volume); #endif barState = State.BarAccumulating; double mod = bars.Instrument.MasterInstrument.Round2TickSize(close % brickSize); double mid = bars.Instrument.MasterInstrument.Compare(mod, brickSize) == 0 ? close : close - mod; renkoHigh = mid + brickSize; renkoLow = mid - brickSize; } else { if (barState == State.BarComplete) { // this tick creates a new bar #if NT7 AddBar(bars, close, close, close, close, time, volume, isRealtime); #else AddBar(bars, close, close, close, close, time, volume); #endif if (RangeExceeded(bars, close)) { MoveLimits(bars, close, brickSize); } } else { if (RangeExceeded(bars, close)) { #if NT7 AddBar(bars, close, close, close, close, time, volume, isRealtime); #else AddBar(bars, close, close, close, close, time, volume); #endif MoveLimits(bars, close, brickSize); } else { Data.Bar bar = (Bar)bars.Get(bars.Count - 1); #if NT7 UpdateBar(bars, bar.Open, (close > bar.High ? close : bar.High), (close < bar.Low ? close : bar.Low), close, time, volume, isRealtime); #else UpdateBar(bars, bar.Open, (close > bar.High ? close : bar.High), (close < bar.Low ? close : bar.Low), close, time, volume); #endif } } CheckBarComplete(bars, close, brickSize); } #if NT7 bars.LastPrice = close; #endif }
public override void Add(Data.Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isRealtime)
/// <summary> /// </summary> /// <param name="bars"></param> /// <param name="open"></param> /// <param name="high"></param> /// <param name="low"></param> /// <param name="close"></param> /// <param name="time"></param> /// <param name="volume"></param> /// <param name="isRealtime"></param> public override void Add(Data.Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isRealtime) { if ((curdat == null) || (time < curdat.dt)) { extdat.Clear(); extdat.TrimExcess(); curdat = null; tickSize = bars.Instrument.MasterInstrument.TickSize; if (bars.Period.Value > 100) { tlb = true; period = bars.Period.Value - 100; } else { tlb = false; period = bars.Period.Value; } } if (bars.Count == 0 || bars.IsNewSession(time, isRealtime)) { AddBar(bars, open, high, low, close, time, volume, isRealtime); lastBarTime = time; RWTAddExtDat(time, close, volume); } else { Data.Bar bar = (Bar)bars.Get(bars.Count - 1); double rangeValue = Math.Floor(10000000.0 * period * tickSize) / 10000000.0; if (curdat == null) { RWTAddExtDat(time, close, 0); } curdat.dt = time; double reverseRange = rangeValue * (tlb?3.0:1.0); if ((bars.Instrument.MasterInstrument.Compare(close, bar.Open + (lastBarUP?rangeValue:reverseRange)) > 0) && (lastBarUP || ((time.Ticks - lastBarTime.Ticks) > 10000000L))) { bool isFirstNewBar = true; double newBarOpen = bar.Open + (lastBarUP?rangeValue:reverseRange); double newClose = Math.Min(close, newBarOpen + rangeValue); UpdateBar(bars, bar.Open, newBarOpen, bar.Low, newBarOpen, time, 0, isRealtime); curdat.addLevel(1); do { AddBar(bars, newBarOpen, newClose, newBarOpen, newClose, time, isFirstNewBar ? volume : 0, isRealtime); RWTAddExtDat(time, newClose, (isFirstNewBar ? volume : 0)); if (bars.Instrument.MasterInstrument.Compare(close, newClose) == 0) { break; } newBarOpen = newClose; newClose = Math.Min(close, newBarOpen + rangeValue); isFirstNewBar = false; }while (true); prices[1] = newClose; lastMoveUp = true; lastBarUP = true; lastBarTime = time; } else if ((bars.Instrument.MasterInstrument.Compare(bar.Open - (lastBarUP?reverseRange:rangeValue), close) > 0) && ((!lastBarUP) || ((time.Ticks - lastBarTime.Ticks) > 10000000L))) { bool isFirstNewBar = true; double newBarOpen = bar.Open - (lastBarUP?reverseRange:rangeValue); double newClose = Math.Max(close, newBarOpen - rangeValue); UpdateBar(bars, bar.Open, bar.High, newBarOpen, newBarOpen, time, 0, isRealtime); curdat.addLevel(-1); do { AddBar(bars, newBarOpen, newBarOpen, newClose, newClose, time, isFirstNewBar ? volume : 0, isRealtime); RWTAddExtDat(time, newClose, (isFirstNewBar ? volume : 0)); if (bars.Instrument.MasterInstrument.Compare(close, newClose) == 0) { break; } newBarOpen = newClose; newClose = Math.Max(close, newBarOpen - rangeValue); isFirstNewBar = false; }while (true); prices[0] = newClose; lastMoveUp = false; lastBarUP = false; lastBarTime = time; } else { UpdateBar(bars, bar.Open, Math.Max(bar.High, close), Math.Min(bar.Low, close), close, time, volume, isRealtime); RWTUpdateCounts(close); RWTUpdateCurdat(close, volume); } } bars.LastPrice = close; // update the extended data... prevClose = close; }
public override double GetPercentComplete(Data.Bars bars, DateTime now) { //throw new ApplicationException("GetPercentComplete not supported in " + DisplayName); return(barState == State.BarComplete ? 100 : 0); }
/// <summary> /// </summary> /// <param name="bars"></param> /// <param name="open"></param> /// <param name="high"></param> /// <param name="low"></param> /// <param name="close"></param> /// <param name="time"></param> /// <param name="volume"></param> /// <param name="isRealtime"></param> public override void Add(Data.Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isRealtime) { if (tickSize == 0) { tickSize = bars.Instrument.MasterInstrument.TickSize; if (bars.Period.Value > 100) { tlb = true; period = bars.Period.Value - 100; } else { tlb = false; period = bars.Period.Value; } } if (bars.Count == 0 || bars.IsNewSession(time, isRealtime)) { AddBar(bars, open, high, low, close, time, volume, isRealtime); lastBarTime = time; } else { Data.Bar bar = (Bar)bars.Get(bars.Count - 1); double rangeValue = Math.Floor(10000000.0 * period * tickSize) / 10000000.0; double reverseRange = rangeValue * (tlb?3.0:1.0); if ((bars.Instrument.MasterInstrument.Compare(close, bar.Open + (lastBarUP?rangeValue:reverseRange)) > 0) && (lastBarUP || ((time.Ticks - lastBarTime.Ticks) > 10000000L))) { bool isFirstNewBar = true; double newBarOpen = bar.Open + (lastBarUP?rangeValue:reverseRange); double newClose = Math.Min(close, newBarOpen + rangeValue); UpdateBar(bars, bar.Open, newBarOpen, bar.Low, newBarOpen, time, 0, isRealtime); do { AddBar(bars, newBarOpen, newClose, newBarOpen, newClose, time, isFirstNewBar ? volume : 0, isRealtime); if (bars.Instrument.MasterInstrument.Compare(close, newClose) == 0) { break; } newBarOpen = newClose; newClose = Math.Min(close, newBarOpen + rangeValue); isFirstNewBar = false; }while (true); lastBarUP = true; lastBarTime = time; } else if ((bars.Instrument.MasterInstrument.Compare(bar.Open - (lastBarUP?reverseRange:rangeValue), close) > 0) && ((!lastBarUP) || ((time.Ticks - lastBarTime.Ticks) > 10000000L))) { bool isFirstNewBar = true; double newBarOpen = bar.Open - (lastBarUP?reverseRange:rangeValue); double newClose = Math.Max(close, newBarOpen - rangeValue); UpdateBar(bars, bar.Open, bar.High, newBarOpen, newBarOpen, time, 0, isRealtime); do { AddBar(bars, newBarOpen, newBarOpen, newClose, newClose, time, isFirstNewBar ? volume : 0, isRealtime); if (bars.Instrument.MasterInstrument.Compare(close, newClose) == 0) { break; } newBarOpen = newClose; newClose = Math.Max(close, newBarOpen - rangeValue); isFirstNewBar = false; }while (true); lastBarUP = false; lastBarTime = time; } else { UpdateBar(bars, bar.Open, Math.Max(bar.High, close), Math.Min(bar.Low, close), close, time, volume, isRealtime); } } bars.LastPrice = close; }
/// <summary> /// </summary> /// <param name="bars"></param> /// <param name="open"></param> /// <param name="high"></param> /// <param name="low"></param> /// <param name="close"></param> /// <param name="time"></param> /// <param name="volume"></param> /// <param name="isRealtime"></param> public override void Add(Data.Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isRealtime) { if ((curdat == null) || (time < curdat.dt)) { extdat.Clear(); extdat.TrimExcess(); curdat = null; tickSize = bars.Instrument.MasterInstrument.TickSize; } if (bars.Count == 0 || bars.IsNewSession(time, isRealtime)) { AddBar(bars, open, high, low, close, time, volume, isRealtime); lastBarTime = time; RWTAddExtDat(time, close, volume); } else { Data.Bar bar = (Bar)bars.Get(bars.Count - 1); //double tickSize = bars.Instrument.MasterInstrument.TickSize; double rangeValue = Math.Floor(10000000.0 * (double)bars.Period.Value * tickSize) / 10000000.0; if (curdat == null) { RWTAddExtDat(time, close, 0); } curdat.dt = time; if ((bars.Instrument.MasterInstrument.Compare(close, bar.Low + rangeValue) > 0) && (lastBarUP || ((time.Ticks - lastBarTime.Ticks) > 10000000L))) { bool isFirstNewBar = true; double newClose = bar.Low + rangeValue; // every bar closes either with high or low UpdateBar(bars, bar.Open, newClose, bar.Low, newClose, time, 0, isRealtime); curdat.addLevel(1); // if still gap, fill with phantom bars double newBarOpen = newClose + tickSize; while (bars.Instrument.MasterInstrument.Compare(close, newClose) > 0) { newClose = Math.Min(close, newBarOpen + rangeValue); AddBar(bars, newBarOpen, newClose, newBarOpen, newClose, time, isFirstNewBar ? volume : 1, isRealtime); RWTAddExtDat(time, newClose, (isFirstNewBar?volume:0)); newBarOpen = newClose + tickSize; isFirstNewBar = false; } prices[1] = newClose; lastMoveUp = true; lastBarUP = true; lastBarTime = time; } else if ((bars.Instrument.MasterInstrument.Compare(bar.High - rangeValue, close) > 0) && ((!lastBarUP) || ((time.Ticks - lastBarTime.Ticks) > 10000000L))) { bool isFirstNewBar = true; double newClose = bar.High - rangeValue; // every bar closes either with high or low UpdateBar(bars, bar.Open, bar.High, newClose, newClose, time, 0, isRealtime); curdat.addLevel(-1); // if still gap, fill with phantom bars double newBarOpen = newClose - tickSize; while (bars.Instrument.MasterInstrument.Compare(newClose, close) > 0) { newClose = Math.Max(close, newBarOpen - rangeValue); AddBar(bars, newBarOpen, newBarOpen, newClose, newClose, time, isFirstNewBar ? volume : 1, isRealtime); RWTAddExtDat(time, newClose, (isFirstNewBar?volume:0)); newBarOpen = newClose - tickSize; isFirstNewBar = false; } prices[0] = newClose; lastMoveUp = false; lastBarUP = false; lastBarTime = time; } else { UpdateBar(bars, open, (close > bar.High ? close : bar.High), (close < bar.Low ? close : bar.Low), close, time, volume, isRealtime); RWTUpdateCounts(close); RWTUpdateCurdat(close, volume); } } bars.LastPrice = close; // update the extended data... prevClose = close; }