Ejemplo n.º 1
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;
            }

            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;
        }
Ejemplo n.º 2
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;
            }

            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;
        }
Ejemplo n.º 3
0
        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
        }
Ejemplo n.º 4
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;
            }
            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;
        }
Ejemplo n.º 5
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;
                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;
        }
Ejemplo n.º 6
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;
        }