Exemplo n.º 1
0
        private void OnTradeBar(ITradeBar newCandle)
        {
            DateTime tclose = newCandle.Time;
            DateTime topen  = newCandle.OpenTime;

            if (FormingCandle == null)
            {
                //tbere isn't any currently forming candle, create one using new candle as generator
                var opeTime = GetOpenTime(newCandle.CloseTime, Resolution);
                FormingCandle = new Candlestick(opeTime, newCandle, Resolution);
            }
            if (topen >= FormingCandle.CloseTime || tclose > FormingCandle.CloseTime)
            {
                //old candle is ended, the new candle is already part of the next one
                OnConsolidated?.Invoke(FormingCandle);
                //use new candle as generator
                var opeTime = GetOpenTime(newCandle.CloseTime, Resolution);
                FormingCandle = new Candlestick(opeTime, newCandle, Resolution);
            }
            else
            {
                //the new candle is part of the forming candle
                FormingCandle.Merge(newCandle);
                //check if candle is completed and emit it
                if (tclose == FormingCandle.Time)
                {
                    OnConsolidated?.Invoke(FormingCandle);
                    FormingCandle = null;
                }
            }
        }
Exemplo n.º 2
0
 public void Scan(DateTime timeNow)
 {
     if (FormingCandle != null && timeNow >= FormingCandle.Time)
     {
         OnConsolidated?.Invoke(FormingCandle);
         FormingCandle = null;
     }
 }