/// <summary>
    /// logic open position
    /// логика открытия первой позиции и дополнительного входа
    /// </summary>
    private void LogicOpenPosition(List <Candle> candles)
    {
        List <Position> openPositions = _tab.PositionsOpenAll;

        if (openPositions == null || openPositions.Count == 0)
        {
            _tab.BuyAtStopCancel();
            _tab.SellAtStopCancel();
            // long
            if (Regime.ValueString != "OnlyShort")
            {
                decimal priceEnter = _lastPcUp;
                _tab.BuyAtStop(VolumeFix1.ValueDecimal,
                               priceEnter + Slippage.ValueInt * _tab.Securiti.PriceStep,
                               priceEnter, StopActivateType.HigherOrEqual);
            }

            // Short
            if (Regime.ValueString != "OnlyLong")
            {
                decimal priceEnter = _lastPcDown;
                _tab.SellAtStop(VolumeFix1.ValueDecimal,
                                priceEnter - Slippage.ValueInt * _tab.Securiti.PriceStep,
                                priceEnter, StopActivateType.LowerOrEqyal);
            }
            return;
        }

        if (openPositions.Count == 1)
        {
            _tab.BuyAtStopCancel();
            _tab.SellAtStopCancel();
            if (openPositions[0].Direction == Side.Buy)
            {
                decimal priceEnter = _lastPcUp + (_lastAtr * KofAtr.ValueDecimal);
                _tab.BuyAtStop(VolumeFix2.ValueDecimal,
                               priceEnter + Slippage.ValueInt * _tab.Securiti.PriceStep,
                               priceEnter, StopActivateType.HigherOrEqual);
            }
            else
            {
                decimal priceEnter = _lastPcDown - (_lastAtr * KofAtr.ValueDecimal);
                _tab.SellAtStop(VolumeFix2.ValueDecimal,
                                priceEnter - Slippage.ValueInt * _tab.Securiti.PriceStep,
                                priceEnter, StopActivateType.LowerOrEqyal);
            }
        }
    }
Example #2
0
        /// <summary>
        /// logic open position
        /// логика открытия первой позиции и дополнительного входа
        /// </summary>
        private void LogicOpenPosition(List <Candle> candles)
        {
            if (_LastCandleTime != candles[candles.Count - 1].TimeStart)
            {
                _LastCandleTime = candles[candles.Count - 1].TimeStart;
            }
            else
            {
                return;
            }
            List <Position> openPositions = _tab.PositionsOpenAll;

            if (openPositions == null || openPositions.Count == 0)
            {
                // long
                if (Regime.ValueString != "OnlyShort" && _lastTrendDown != 0 && _lastfastma > _lastslowma)
                {
                    decimal priceEnter = _lastTrendDown;
                    _tab.BuyAtStop(GetVolume(Side.Buy), priceEnter + Slipage.ValueDecimal, priceEnter, StopActivateType.LowerOrEqyal, 1);
                }

                // Short
                if (Regime.ValueString != "OnlyLong" && _lastTrendUp != 0 && _lastfastma < _lastslowma)
                {
                    decimal priceEnter = _lastTrendUp;
                    _tab.SellAtStop(GetVolume(Side.Sell), priceEnter - Slipage.ValueDecimal, priceEnter, StopActivateType.HigherOrEqual, 1);
                }
                return;
            }
        }
Example #3
0
        /// <summary>
        /// logic open position
        /// логика открытия первой позиции и дополнительного входа
        /// </summary>
        private void LogicOpenPosition(List <Candle> candles)
        {
            if (_LastCandleTime != candles[candles.Count - 1].TimeStart)
            {
                _LastCandleTime = candles[candles.Count - 1].TimeStart;
            }
            else
            {
                return;
            }
            List <Position> openPositions = _tab.PositionsOpenAll;

            if (openPositions == null || openPositions.Count == 0)
            {
                // long
                if (Regime.ValueString != "OnlyShort")
                {
                    decimal priceEnter = _lastPcUp + (_lastAtr * KofAtr);
                    _tab.BuyAtStop(VolumeFix1.ValueDecimal, priceEnter + Slipage.ValueDecimal, priceEnter, StopActivateType.HigherOrEqual);
                }

                // Short
                if (Regime.ValueString != "OnlyLong")
                {
                    decimal priceEnter = _lastPcDown - (_lastAtr * KofAtr);
                    _tab.SellAtStop(VolumeFix1.ValueDecimal, priceEnter - Slipage.ValueDecimal, priceEnter, StopActivateType.LowerOrEqyal);
                }
                return;
            }

            openPositions = _tab.PositionsOpenAll;
            for (int i = 0; openPositions != null && i < openPositions.Count; i++)
            {
                if (openPositions[i].State == PositionStateType.Open)
                {
                    if (openPositions[i].Direction == Side.Buy)
                    {
                        if (openPositions[i].OpenVolume < (VolumeFix1.ValueDecimal + VolumeFix2.ValueDecimal) &&
                            candles[candles.Count - 1].Close < _lastPcUp - (_lastAtr * KofAtr))
                        {
                            decimal priceEnter = _lastPcUp - (_lastAtr * KofAtr);
                            _tab.BuyAtLimitToPosition(openPositions[i], priceEnter, VolumeFix2.ValueDecimal);
                        }
                    }
                    else
                    {
                        if (openPositions[i].OpenVolume <(VolumeFix1.ValueDecimal + VolumeFix2.ValueDecimal) &&
                                                         candles[candles.Count - 1].Close> _lastPcUp - (_lastAtr * KofAtr))
                        {
                            decimal priceEnter = _lastPcDown + (_lastAtr * KofAtr);
                            _tab.SellAtLimitToPosition(openPositions[i], priceEnter, VolumeFix2.ValueDecimal);
                        }
                    }
                }
            }
        }
Example #4
0
        private void OpenAtLevel()
        {
            if (!CanOpenPosition())
            {
                return;
            }
            PriceLevleLine.levlel lvl = PriceLevleLine.LevleData.FindLast(x => x.levlSide == TradeSide);
            if (lvl != null)
            {
                if (TradeSide == Side.Buy)
                {
                    // покупаем по возвращению цены
                    _tab.BuyAtStop(_Volume.ValueDecimal, lvl.Value, lvl.Value, StopActivateType.LowerOrEqyal);
                }
                if (TradeSide == Side.Sell)
                {
                    // Продаем по возвращению цены
                    _tab.SellAtStop(_Volume.ValueDecimal, lvl.Value, lvl.Value, StopActivateType.HigherOrEqual);
                }
            }

            lvl = PriceLevleLine.LevleData.FindLast(x => x.levlSide != TradeSide);
            if (lvl != null)
            {
                if (TradeSide == Side.Buy)
                {
                    // покупаем попробитию последнего максимума
                    _tab.BuyAtStop(_Volume.ValueDecimal, lvl.Value + lvl.Value * 0.005m, lvl.Value, StopActivateType.LowerOrEqyal);
                }
                if (TradeSide == Side.Sell)
                {
                    // Проадем попробитию последнего минимума
                    _tab.SellAtStop(_Volume.ValueDecimal, lvl.Value - lvl.Value * 0.005m, lvl.Value, StopActivateType.HigherOrEqual);
                }
            }
        }
Example #5
0
        /// <summary>
        /// logic open position
        /// логика открытия первой позиции и дополнительного входа
        /// </summary>
        private void LogicOpenPosition(List <Candle> candles)
        {
            _tab.SellAtStopCancel();
            _tab.BuyAtStopCancel();
            if (_LastCandleTime != candles[candles.Count - 1].TimeStart)
            {
                _LastCandleTime = candles[candles.Count - 1].TimeStart;
            }
            else
            {
                return;
            }
            List <Position> openPositions = _tab.PositionsOpenAll;

            if (openPositions == null || openPositions.Count == 0)
            {
                // long
                if (Regime.ValueString != "OnlyShort")
                {
                    if (FastMA.Values[FastMA.Values.Count - 1] > SlowMA.Values[SlowMA.Values.Count - 1]

                        )
                    {
                        decimal priceEnter = _lastPcUp + (_lastAtr * KofAtr);
                        //   priceEnter = GetLastFractail(Fractail.ValuesUp);
                        //_tab.BuyAtStop(VolumeFix1.ValueDecimal, priceEnter + Slipage.ValueDecimal, priceEnter, StopActivateType.HigherOrEqual);
                        _tab.BuyAtStop(GetVolume(Side.Buy), priceEnter + Slipage.ValueDecimal, priceEnter, StopActivateType.HigherOrEqual);
                    }
                }

                // Short
                if (Regime.ValueString != "OnlyLong")
                {
                    if (FastMA.Values[FastMA.Values.Count - 1] < SlowMA.Values[SlowMA.Values.Count - 1]

                        )
                    {
                        decimal priceEnter = _lastPcDown - (_lastAtr * KofAtr);
                        //   priceEnter = GetLastFractail(Fractail.ValuesDown);
                        //_tab.SellAtStop(VolumeFix1.ValueDecimal, priceEnter - Slipage.ValueDecimal, priceEnter, StopActivateType.LowerOrEqyal);
                        _tab.SellAtStop(GetVolume(Side.Sell), priceEnter - Slipage.ValueDecimal, priceEnter, StopActivateType.LowerOrEqyal);
                    }
                }
                return;
            }
        }
Example #6
0
    private void LogicOpenPosition(List <Candle> candles)
    {
        decimal lastMa = _sma.DataSeries[0].Values[_sma.DataSeries[0].Values.Count - 1];

        decimal lastPrice = candles[candles.Count - 1].Close;

        if (lastMa == 0)
        {
            return;
        }

        decimal maxToCandleSeries = _channel.DataSeries[0].Values[_channel.DataSeries[0].Values.Count - 1];
        decimal minToCandleSeries = _channel.DataSeries[1].Values[_channel.DataSeries[1].Values.Count - 1];

        List <Position> positions = _tab.PositionsOpenAll;

        if (lastPrice >= lastMa && Regime.ValueString != "OnlyShort")
        {
            if (positions != null && positions.Count != 0 &&
                positions[0].Direction == Side.Buy)
            {
                if (positions.Count >= MaximumPosition.ValueInt)
                {
                    return;
                }
                decimal lastIntro = positions[positions.Count - 1].EntryPrice;
                if (lastIntro + lastIntro * (PersentDopSell.ValueDecimal / 100) < lastPrice)
                {
                    if (positions.Count >= MaximumPosition.ValueInt)
                    {
                        return;
                    }
                    _tab.BuyAtLimit(Volume.ValueDecimal, lastPrice + (Slippage.ValueInt * _tab.Securiti.PriceStep));
                }
            }
            else if (positions == null || positions.Count == 0)
            {
                _tab.SellAtStopCancel();
                _tab.BuyAtStopCancel();
                _tab.BuyAtStop(Volume.ValueDecimal, maxToCandleSeries + (Slippage.ValueInt * _tab.Securiti.PriceStep), maxToCandleSeries, StopActivateType.HigherOrEqual);
            }
        }

        if (lastPrice <= lastMa && Regime.ValueString != "OnlyLong")
        {
            if (positions != null && positions.Count != 0 &&
                positions[0].Direction == Side.Sell)
            {
                if (positions.Count >= MaximumPosition.ValueInt)
                {
                    return;
                }
                decimal lastIntro = positions[positions.Count - 1].EntryPrice;

                if (lastIntro - lastIntro * (PersentDopSell.ValueDecimal / 100) > lastPrice)
                {
                    _tab.SellAtLimit(Volume.ValueDecimal, lastPrice - (Slippage.ValueInt * _tab.Securiti.PriceStep));
                }
            }
            else if (positions == null || positions.Count == 0)
            {
                if (positions != null && positions.Count >= MaximumPosition.ValueInt)
                {
                    return;
                }

                _tab.SellAtStopCancel();
                _tab.BuyAtStopCancel();
                _tab.SellAtStop(Volume.ValueDecimal, minToCandleSeries - (Slippage.ValueInt * _tab.Securiti.PriceStep), minToCandleSeries, StopActivateType.LowerOrEqyal);
            }
        }
    }
Example #7
0
        /// <summary>
        /// проверить условия на открытие позиции
        /// </summary>
        private void TryOpenPosition(List <Candle> candles, Side openSide)
        {
            // БАЙ
            if (openSide != Side.Buy)
            {
                decimal lineBuy = GetPriceToOpenPos(Side.Buy, _downChanel.Count - 1);

                if (lineBuy == 0)
                {
                    return;
                }

                if (lineBuy + _tab.Securiti.PriceStep * 5 < candles[candles.Count - 1].Close)
                {// это костыль, основной вход через отложенный ордер.
                 // т.к. в Велсе тип заявки: СтопМаркет(по любой цене). А у нас СтопЛимит(с проскальзываниями и отступами)
                 // чтобы было хоть немного похоже, если стоп на открытие у нас уже в деньгах
                 // выставляемся по закрытию свечи.
                 // в этом случае Велс просто рисует вход по открытию свечи!

                    _tab.BuyAtLimit(Volume, candles[candles.Count - 1].Close + _tab.Securiti.PriceStep * 10);
                    return;
                }

                decimal priceOrder   = lineBuy + _tab.Securiti.PriceStep * SlipageOpenFirst; // ЗДЕСЬ!!!!!!!!!!!!!!
                decimal priceRedLine = lineBuy - _tab.Securiti.PriceStep * SlipageReversOpen;


                _tab.BuyAtStop(Volume, priceOrder, priceRedLine, StopActivateType.HigherOrEqual);

                if (StartProgram != StartProgram.IsTester && AlertIsOn)
                {
                    _alert.PriceActivation = priceRedLine - SlipageToAlert * _tab.Securiti.PriceStep;
                    _alert.TypeActivation  = PriceAlertTypeActivation.PriceHigherOrEqual;
                    _alert.MessageIsOn     = true;
                    _alert.MusicType       = AlertMusic.Duck;
                    _alert.Message         = "Приближаемся к точке выхода";
                    _alert.IsOn            = true;
                }
            }

            // СЕЛЛ
            if (openSide != Side.Sell)
            {
                decimal lineSell = GetPriceToOpenPos(Side.Sell, _downChanel.Count - 1);

                if (lineSell == 0)
                {
                    return;
                }

                if (lineSell - _tab.Securiti.PriceStep * 5 > candles[candles.Count - 1].Close)
                {// это костыль, основной вход через отложенный ордер.
                 // т.к. в Велсе тип заявки: СтопМаркет(по любой цене). А у нас СтопЛимит(с проскальзываниями и отступами)
                 // чтобы было хоть немного похоже, если стоп на открытие у нас уже в деньгах
                 // выставляемся по закрытию свечи.
                 // в этом случае Велс просто рисует вход по открытию свечи!

                    _tab.SellAtLimit(Volume, candles[candles.Count - 1].Close - _tab.Securiti.PriceStep * 10);
                    return;
                }

                decimal priceOrderSell   = lineSell - _tab.Securiti.PriceStep * SlipageOpenFirst; // ЗДЕСЬ!!!!!!!!!!!!!!
                decimal priceRedLineSell = lineSell + _tab.Securiti.PriceStep * SlipageReversOpen;

                _tab.SellAtStop(Volume, priceOrderSell, priceRedLineSell, StopActivateType.LowerOrEqyal);

                if (StartProgram != StartProgram.IsTester && AlertIsOn)
                {
                    _alert.PriceActivation = priceRedLineSell + SlipageToAlert * _tab.Securiti.PriceStep;
                    _alert.TypeActivation  = PriceAlertTypeActivation.PriceLowerOrEqual;
                    _alert.MessageIsOn     = true;
                    _alert.MusicType       = AlertMusic.Duck;
                    _alert.Message         = "Приближаемся к точке выхода";
                    _alert.IsOn            = true;
                }
            }
        }
Example #8
0
        /// <summary>
        /// проверить условия для входа в позицию
        /// </summary>
        private void TryOpenPosition(List <Candle> candles)
        {
            // _tab.BuyAtLimit(Volume, candles[candles.Count - 1].Close - _tab.Securiti.PriceStep * 50);

            // return;
            decimal lastAdx = ((Adx)_adx).Values[candles.Count - 1];

            if (lastAdx == 0 ||
                ((Adx)_adx).Values.Count + 1 < Lookback)
            {
                return;
            }

            if (candles.Count < 23)
            {
                return;
            }

            decimal adxMax = 0;

            for (int i = ((Adx)_adx).Values.Count - 1; i > ((Adx)_adx).Values.Count - 1 - Lookback && i > 0; i--)
            {
                decimal value = ((Adx)_adx).Values[i];

                if (value > adxMax)
                {
                    adxMax = value;
                }
            }

            if (adxMax > AdxHigh)
            {
                return;
            }


            if (EmulatorIsOn)
            {
                int currentEmuPos = GetCurrentPosition();
                if (currentEmuPos != 0)
                {
                    return;
                }
            }

            // БАЙ

            decimal lineBuy = GetPriceToOpenPos(Side.Buy, candles, candles.Count - 1);

            if (lineBuy + _tab.Securiti.PriceStep * 5 < candles[candles.Count - 1].Close)
            {// это костыль, основной вход через отложенный ордер.
             // т.к. в Велсе тип заявки: СтопМаркет(по любой цене). А у нас СтопЛимит(с проскальзываниями и отступами)
             // чтобы было хоть немного похоже, если стоп на открытие у нас уже в деньгах
             // выставляемся по закрытию свечи.
             // в этом случае Велс просто рисует вход по открытию свечи!

                _tab.BuyAtLimit(Volume, candles[candles.Count - 1].Close + _tab.Securiti.PriceStep * 10);
                return;
            }

            decimal priceOrder   = lineBuy + _tab.Securiti.PriceStep * SlipageOpenFirst; // ЗДЕСЬ!!!!!!!!!!!!!!
            decimal priceRedLine = lineBuy - _tab.Securiti.PriceStep * SlipageReversOpen;


            _tab.BuyAtStop(Volume, priceOrder, priceRedLine, StopActivateType.HigherOrEqual);

            if (StartProgram != StartProgram.IsTester && AlertIsOn)
            {
                _alert.PriceActivation = priceRedLine - SlipageToAlert * _tab.Securiti.PriceStep;
                _alert.TypeActivation  = PriceAlertTypeActivation.PriceHigherOrEqual;
                _alert.MessageIsOn     = true;
                _alert.MusicType       = AlertMusic.Duck;
                _alert.Message         = "Приближаемся к точке входа";
                _alert.IsOn            = true;
            }

            // СЕЛЛ

            decimal lineSell = GetPriceToOpenPos(Side.Sell, candles, candles.Count - 1);

            if (lineSell - _tab.Securiti.PriceStep * 5 > candles[candles.Count - 1].Close)
            {// это костыль, основной вход через отложенный ордер.
             // т.к. в Велсе тип заявки: СтопМаркет(по любой цене). А у нас СтопЛимит(с проскальзываниями и отступами)
             // чтобы было хоть немного похоже, если стоп на открытие у нас уже в деньгах
             // выставляемся по закрытию свечи.
             // в этом случае Велс просто рисует вход по открытию свечи!

                _tab.SellAtLimit(Volume, candles[candles.Count - 1].Close - _tab.Securiti.PriceStep * 10);
                return;
            }

            decimal priceOrderSell   = lineSell - _tab.Securiti.PriceStep * SlipageOpenFirst; // ЗДЕСЬ!!!!!!!!!!!!!!
            decimal priceRedLineSell = lineSell + _tab.Securiti.PriceStep * SlipageReversOpen;

            _tab.SellAtStop(Volume, priceOrderSell, priceRedLineSell, StopActivateType.LowerOrEqyal);

            if (StartProgram != StartProgram.IsTester && AlertIsOn)
            {
                _alert.PriceActivation = priceRedLineSell + SlipageToAlert * _tab.Securiti.PriceStep;
                _alert.TypeActivation  = PriceAlertTypeActivation.PriceLowerOrEqual;
                _alert.MessageIsOn     = true;
                _alert.MusicType       = AlertMusic.Duck;
                _alert.Message         = "Приближаемся к точке входа";
                _alert.IsOn            = true;
            }
        }