コード例 #1
0
 /// <summary>
 /// This function is called by our renkoClose consolidator defined in Initialize()
 /// </summary>
 /// <param name="data">The new renko bar produced by the consolidator</param>
 public void HandleRenkoClose(RenkoBar data)
 {
     if (!Portfolio.Invested)
     {
         SetHoldings(data.Symbol, 1.0);
     }
     Console.WriteLine("CLOSE - {0} - {1} {2}", data.Time.ToString("o"), data.Open, data.Close);
 }
コード例 #2
0
 /// <summary>
 /// This function is called by our renko7bar onsolidator defined in Initialize()
 /// </summary>
 /// <param name="data">The new renko bar produced by the consolidator</param>
 public void HandleRenko7Bar(RenkoBar data)
 {
     Console.WriteLine("7BAR  - {0} - {1} {2}", data.Time.ToString("o"), data.Open, data.Close);
 }
コード例 #3
0
        /// <summary>
        /// Event invocator for the DataConsolidated event. This should be invoked
        /// by derived classes when they have consolidated a new piece of data.
        /// </summary>
        /// <param name="consolidated">The newly consolidated data</param>
        protected virtual void OnDataConsolidated(RenkoBar consolidated)
        {
            var handler = DataConsolidated;
            if (handler != null) handler(this, consolidated);

            var explicitHandler = _dataConsolidatedHandler;
            if (explicitHandler != null) explicitHandler(this, consolidated);

            Consolidated = consolidated;
        }
コード例 #4
0
        private void UpdateClassic(IBaseData data)
        {
            var currentValue = _selector(data);
            var volume = _volumeSelector(data);

            decimal? close = null;
            
            // if we're already in a bar then update it
            if (_currentBar != null)
            {
                _currentBar.Update(data.Time, currentValue, volume);

                // if the update caused this bar to close, fire the event and reset the bar
                if (_currentBar.IsClosed)
                {
                    close = _currentBar.Close;
                    OnDataConsolidated(_currentBar);
                    _currentBar = null;
                }
            }

            if (_currentBar == null)
            {
                var open = close ?? currentValue;
                if (_evenBars && !close.HasValue)
                {
                    open = Math.Ceiling(open/_barSize)*_barSize;
                }
                _currentBar = new RenkoBar(data.Symbol, data.Time, _barSize, open, volume);
            }
        }
コード例 #5
0
        private void UpdateWicked(IBaseData data)
        {
            var rate = data.Price;

            if (_firstTick)
            {
                _firstTick = false;

                _openOn = data.Time;
                _closeOn = data.Time;
                _openRate = rate;
                _highRate = rate;
                _lowRate = rate;
                _closeRate = rate;
            }
            else
            {
                _closeOn = data.Time;

                if (rate > _highRate)
                    _highRate = rate;

                if (rate < _lowRate)
                    _lowRate = rate;

                _closeRate = rate;

                if (_closeRate > _openRate)
                {
                    if (_lastWicko == null ||
                        (_lastWicko.Direction == BarDirection.Rising))
                    {
                        Rising(data);

                        return;
                    }

                    var limit = (_lastWicko.Open + BarSize);

                    if (_closeRate > limit)
                    {
                        var wicko = new RenkoBar(data.Symbol, _openOn, _closeOn,
                            BarSize, _lastWicko.Open, limit, _lowRate, limit);

                        _lastWicko = wicko;

                        OnDataConsolidated(wicko);

                        _openOn = _closeOn;
                        _openRate = limit;
                        _lowRate = limit;

                        Rising(data);
                    }
                }
                else if (_closeRate < _openRate)
                {
                    if (_lastWicko == null ||
                        (_lastWicko.Direction == BarDirection.Falling))
                    {
                        Falling(data);

                        return;
                    }

                    var limit = (_lastWicko.Open - BarSize);

                    if (_closeRate < limit)
                    {
                        var wicko = new RenkoBar(data.Symbol, _openOn, _closeOn,
                            BarSize, _lastWicko.Open, _highRate, limit, limit);

                        _lastWicko = wicko;

                        OnDataConsolidated(wicko);

                        _openOn = _closeOn;
                        _openRate = limit;
                        _highRate = limit;

                        Falling(data);
                    }
                }
            }
        }
コード例 #6
0
        private void Falling(IBaseData data)
        {
            decimal limit;

            while (_closeRate < (limit = (_openRate - BarSize)))
            {
                var wicko = new RenkoBar(data.Symbol, _openOn, _closeOn,
                    BarSize, _openRate, _highRate, limit, limit);

                _lastWicko = wicko;

                OnDataConsolidated(wicko);

                _openOn = _closeOn;
                _openRate = limit;
                _highRate = limit;
            }
        }