private void TLastCUpdate(object state)
        {
            if (LockCandlesUpdate)
            {
                return;
            }

            if (Candles.Count == 0)
            {
                return;
            }

            LockCandlesUpdate = true;

            Ticker tmp = Stock.GetMarketPrice(Param.Market, Print).Result;

            if (tmp == null)
            {
                LockCandlesUpdate = false;
                return;
            }
            decimal price = (tmp.Ask + tmp.Bid) / 2;

            Candles.Last().Close = price;

            OnUpdateCandles(Candles);
            LockCandlesUpdate = false;
        }
        private async Task UpdateCandles()
        {
            Candles = await Stock.GetCandles(Param.Market, Param.Interval, 50, Print);

            if (Candles != null)
            {
                LastCandleTime = Candles.Last().Time;
                Print(string.Format("Загружено {0} свечей.", Candles.Count), true);
            }
        }
Пример #3
0
        private void BuildHekinAshiCandle()
        {
            if (Candles.Count == 0)
            {
                return;
            }
            var candle     = Candles.Last();
            var heikinAshi = new Candle();

            if (HeikinAshi.Count == 0)
            {
                heikinAshi.Open  = (candle.Open + candle.Close) / 2;
                heikinAshi.Close = (candle.Open + candle.Close + candle.High + candle.Low) / 4.0m;
                heikinAshi.High  = candle.High;
                heikinAshi.Low   = candle.Low;
            }
            else
            {
                var lastHeikinAshi = HeikinAshi.Last();
                heikinAshi.Open  = (lastHeikinAshi.Open + lastHeikinAshi.Close) / 2;
                heikinAshi.Close = (candle.Open + candle.Close + candle.High + candle.Low) / 4.0m;
                heikinAshi.High  = Math.Max(Math.Max(heikinAshi.Open, heikinAshi.Close), candle.High);
                heikinAshi.Low   = Math.Min(Math.Min(heikinAshi.Open, heikinAshi.Close), candle.Low);
            }
            ulong netVolume = candle.Volume;

            if (HeikinAshi.Count > 2)
            {
                netVolume = candle.Volume - HeikinAshi.ElementAt(HeikinAshi.Count - 2).Volume;
            }
            heikinAshi.CandleVolume = netVolume;
            heikinAshi.Volume       = candle.Volume;
            heikinAshi.TimeStamp    = candle.TimeStamp;

            heikinAshi.Index = (uint)HeikinAshi.Count;
            this.heikinAshi.Add(heikinAshi);
        }