Esempio 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, 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);
                }
            }
        }
Esempio 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;
         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;
 }
Esempio 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
        }
Esempio 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;
        }
Esempio 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;
        }
Esempio 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;
        }