Exemplo n.º 1
0
        private void Process(Candle candle)
        {
            //this.AddInfoLog("Свеча {0}: {1};{2};{3};{4}; объем {5}", candle.OpenTime, candle.OpenPrice, candle.HighPrice, candle.LowPrice, candle.ClosePrice, candle.TotalVolume);

            var isShortWasFormed = _shortSma.IsFormed;
            var isLongWasFormed  = _longSma.IsFormed;

            var currentShort = _shortSma.Process(candle);
            var currentLong  = _longSma.Process(candle);

            if (candle.State == CandleStates.Finished && isShortWasFormed && isLongWasFormed &&
                _longSma.Length > 1 && _shortSma.Length > 1 && candle.OpenTime > StartedTime)
            {
                Order order = null;

                var prevShort = _shortSma.GetValue(1);
                var prevLong  = _longSma.GetValue(1);

                if (prevShort < prevLong && currentShort.GetValue <decimal>() > currentLong.GetValue <decimal>() && Position <= 0)
                {
                    this.AddInfoLog(LocalizedStrings.Str3297);
                    order = this.BuyAtMarket(Position == 0 ? Volume : Position.Abs() * 2);
                }
                else if (prevShort > prevLong && currentShort.GetValue <decimal>() < currentLong.GetValue <decimal>() && Position >= 0)
                {
                    this.AddInfoLog(LocalizedStrings.Str3298);
                    order = this.SellAtMarket(Position == 0 ? Volume : Position.Abs() * 2);
                }

                if (order != null)
                {
                    RegisterOrder(order);
                }
            }

            new ChartDrawCommand(candle.OpenTime, new Dictionary <IChartElement, object>
            {
                { _area.Elements[0], candle },
                { _area.Elements[1], currentLong },
                { _area.Elements[2], currentShort },
            }).Process(this);
        }