Exemple #1
0
        // logic логика

        /// <summary>
        /// candle finished event
        /// событие завершения свечи
        /// </summary>
        private void Strateg_CandleFinishedEvent(List <Candle> candles)
        {
            if (Regime.ValueString == "Off")
            {
                return;
            }
            _pc.LenghtUpLine   = LengthUp.ValueInt;
            _pc.LenghtDownLine = LengthDown.ValueInt;
            _pc.Process(candles);
            _atr.Lenght = LengthAtr.ValueInt;
            _atr.Process(candles);
            Fractail.Process(candles);
            if (_pc.ValuesUp == null || _pc.ValuesDown == null || _atr.Values == null)
            {
                return;
            }
            if (GetLastFractail(Fractail.DataSeries.ByName("SeriesUp")) == 0 || GetLastFractail(Fractail.DataSeries.ByName("SeriesDown")) == 0)
            {
                return;
            }
            _lastPcUp   = _pc.ValuesUp[_pc.ValuesUp.Count - 1];
            _lastPcDown = _pc.ValuesDown[_pc.ValuesDown.Count - 1];
            _lastAtr    = _atr.Values[_atr.Values.Count - 1];

            if (_pc.ValuesUp == null || _pc.ValuesDown == null || _pc.ValuesUp.Count < _pc.LenghtUpLine + 1 ||
                _pc.ValuesDown.Count < _pc.LenghtDownLine + 1 || _atr.Values == null || _atr.Values.Count < _atr.Lenght + 1)
            {
                return;
            }

            List <Position> openPositions = _tab.PositionsOpenAll;

            if (openPositions != null && openPositions.Count != 0)
            {
                LogicClosePosition();
            }

            if (Regime.ValueString == "OnlyClosePosition")
            {
                return;
            }
            if (openPositions == null || openPositions.Count == 0)
            {
                LogicOpenPosition(candles);
            }
        }
        private void _tab_CandleFinishedEvent(List <Candle> candles)
        {
            if (stopPositions.Count != 0)
            {
                Filltabel_multi(null);
            }
            _tab.BuyAtStopCancel();
            _tab.SellAtStopCancel();
            CanselOldOrders();

            _envelop.Process(candles);
            _atr.Process(candles);
            _lastUp    = _envelop.ValuesUp[_envelop.ValuesUp.Count - 1];
            _lastDown  = _envelop.ValuesDown[_envelop.ValuesDown.Count - 1];
            _lastClose = candles.Last().Close;
            _lastAtr   = _atr.Values[_atr.Values.Count - 1];

            if (_LastCandleTime != candles[candles.Count - 1].TimeStart)
            {
                _LastCandleTime = candles[candles.Count - 1].TimeStart;
            }
            else
            {
                return;
            }
            if (!ValidateParams())
            {
                return;
            }

            LogicClosePOsition();

            if (Regime.ValueString == "OnlyClosePosition")
            {
                return;
            }

            if (CanTrade())
            {
                LogicOpenPosition(candles);
            }
        }