Exemple #1
0
 public SymbolBar(string code, TimedBar bar)
 {
     this.Code = code;
     this.Bar  = new Bar
     {
         Open   = bar.Open,
         High   = bar.High,
         Low    = bar.Low,
         Close  = bar.Close,
         Volume = bar.Volume,
     };
     this.Time = bar.OpenTime;
 }
Exemple #2
0
        private void M1_Bar(TimedBar m1Bar, bool isPartial)
        {
            var serverTime = Account.ServerTime;

            //if (!IsSamePeriod(m1Bar.Time, Account.ServerTime) && m1Bar.Time < Account.ServerTime)
            //{
            //    logger.LogWarning($"[BAR] Got old {SymbolCode} bar for time {m1Bar.Time } when server time is {Account.ServerTime}");
            //}

            if (m1Bar.OpenTime > ServerTimeFromM1Bar)
            {
                ServerTimeFromM1Bar = m1Bar.OpenTime; // May trigger a bar from previous minute, for all symbols, after a delay (to wait for remaining ticks to come in)
            }

            //#if FromTickToMinute
            if (bar.IsValid && !IsSamePeriod(bar.OpenTime, m1Bar.OpenTime))
            {
                // Immediately Trigger a finished bar even after starting the timer above.
                RaiseTimeFrameBar(bar);
                bar = TimedBar.Invalid;
            }

            if (!bar.IsValid)
            {
                bar = new TimedBar()
                {
                    OpenTime = MarketSeries.TimeFrame.GetPeriodStart(m1Bar.OpenTime),
                    Open     = m1Bar.Open,
                    High     = m1Bar.High,
                    Low      = m1Bar.Low,
                    Close    = m1Bar.Close,
                    Volume   = m1Bar.Volume,
                };
            }
            else
            {
                bar = bar.Merge(m1Bar);
            }

            if (double.IsNaN(bar.Volume)) // REVIEW - is this correct for volume?
            {
                bar.Volume = 1;
            }
            else
            {
                bar.Volume++;
            }
        }
Exemple #3
0
        private void RaiseTimeFrameBar(TimedBar bar, bool finishedBar = true)
        {
            lock (M1BarToTimeFrameBarLock)
            {
                //var bar = tickToMinuteBars[symbolCode];
                if (!bar.IsValid)
                {
                    return;
                }

                var partial = finishedBar ? "" : " PARTIAL";
                Debug.WriteLine($"[M1 to {MarketSeries.ToString()}] {bar}{partial}");

                ((IMarketSeriesInternal)this.MarketSeries).OnBar(bar, finishedBar);

                bar = TimedBar.New;
            }
        }
Exemple #4
0
        public TimedBar Merge(TimedBar next)
        {
            var current = this;

            if (next.OpenTime != null)
            {
                High   = Math.Max(current.High, next.High);
                Low    = Math.Min(current.Low, next.Low);
                Close  = next.Close;
                Volume = current.Volume + next.Volume;
            }

            return(this);

            //return new TimedBar
            //{
            //    OpenTime = current.OpenTime,
            //    Open = current.Open,
            //    Close = next.Close,
            //    High = Math.Max(current.High, next.High),
            //    Low = Math.Min(current.Low, next.Low),
            //    Volume = current.Volume + next.Volume
            //};
        }
Exemple #5
0
 static TimedBar()
 {
     Invalid = New;
 }
Exemple #6
0
 private void M1_Bar(TimedBar m1Bar)
 {
     M1_Bar(m1Bar, false);
 }
Exemple #7
0
 public virtual void OnBar(string symbolCode, TimeFrame timeFrame, TimedBar bar)
 {
 }
Exemple #8
0
 public void OnBar(IMarketSeries series, TimedBar bar)
 {
     OnBar(series.SymbolCode, series.TimeFrame, bar);
 }