Esempio n. 1
0
        /// <summary>
        /// successful position opening
        /// успешное открытие позиции
        /// </summary>
        void _tab_PositionOpeningSuccesEvent(Position position)
        {
            if (position.Direction == Side.Buy)
            {
                _tab.CloseAtStop(position, position.EntryPrice - Stop.ValueInt * _tab.Securiti.PriceStep, position.EntryPrice - Stop.ValueInt * _tab.Securiti.PriceStep);
                _tab.CloseAtProfit(position, position.EntryPrice + Profit.ValueInt * _tab.Securiti.PriceStep, position.EntryPrice + Profit.ValueInt * _tab.Securiti.PriceStep);
            }
            if (position.Direction == Side.Sell)
            {
                _tab.CloseAtStop(position, position.EntryPrice + Stop.ValueInt * _tab.Securiti.PriceStep, position.EntryPrice + Stop.ValueInt * _tab.Securiti.PriceStep);
                _tab.CloseAtProfit(position, position.EntryPrice - Profit.ValueInt * _tab.Securiti.PriceStep, position.EntryPrice - Profit.ValueInt * _tab.Securiti.PriceStep);
            }

            List <Position> positions = _tab.PositionsOpenAll;

            for (int i = 0; i < positions.Count; i++)
            {
                if (positions[i].Number == position.Number)
                {
                    continue;
                }
                if (StartProgram == StartProgram.IsOsTrader)
                {
                    _positionsToClose.Add(positions[i]);
                }
                else
                {
                    _tab.CloseAllOrderToPosition(positions[i]);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// событие открытия новой позиции
        /// </summary>
        void _tab_PositionOpeningSuccesEvent(Position position)
        {
            if (ProfitOrderIsOn)
            {
                if (position.Direction == Side.Buy)
                {
                    decimal stopPrice      = position.EntryPrice + position.EntryPrice * (ProfitOrderValue / 100);
                    decimal stopOrderPrice = stopPrice - _tab.Securiti.PriceStep * ProfitOrderSleepage;

                    _tab.CloseAtProfit(position, stopPrice, stopOrderPrice);
                }
                else if (position.Direction == Side.Sell)
                {
                    decimal stopPrice      = position.EntryPrice - position.EntryPrice * (ProfitOrderValue / 100);
                    decimal stopOrderPrice = stopPrice + _tab.Securiti.PriceStep * ProfitOrderSleepage;
                    _tab.CloseAtProfit(position, stopPrice, stopOrderPrice);
                }
            }

            if (StopOrderIsOn)
            {
                if (position.Direction == Side.Buy)
                {
                    decimal stopPrice      = position.EntryPrice - position.EntryPrice * (StopOrderValue / 100);
                    decimal stopOrderPrice = stopPrice - _tab.Securiti.PriceStep * StopOrderSleepage;
                    _tab.CloseAtStop(position, stopPrice, stopOrderPrice);
                }
                else if (position.Direction == Side.Sell)
                {
                    decimal stopPrice      = position.EntryPrice + position.EntryPrice * (StopOrderValue / 100);
                    decimal stopOrderPrice = stopPrice + _tab.Securiti.PriceStep * StopOrderSleepage;
                    _tab.CloseAtStop(position, stopPrice, stopOrderPrice);
                }
            }
        }
Esempio n. 3
0
    /// <summary>
    /// set stop orders and profit orders
    /// выставление стоп-лосс и таке-профит
    /// </summary>
    private void Strateg_PositionOpen(Position position)
    {
        List <Position> openPositions = _tab.PositionsOpenAll;

        for (int i = 0; openPositions != null && i < openPositions.Count; i++)
        {
            if (openPositions[i].Direction == Side.Buy)
            {
                decimal lowCandle = _tab.CandlesAll[_tab.CandlesAll.Count - 2].Low;
                _tab.CloseAtStop(openPositions[i], lowCandle, lowCandle - Slippage.ValueInt * _tab.Securiti.PriceStep);

                _tab.CloseAtProfit(
                    openPositions[i], _lastPrice + (_lastPcUp - _lastPcDown),
                    (_lastPrice + (_lastPcUp - _lastPcDown)) - Slippage.ValueInt * _tab.Securiti.PriceStep);
            }
            else
            {
                decimal highCandle = _tab.CandlesAll[_tab.CandlesAll.Count - 2].High;
                _tab.CloseAtStop(openPositions[i], highCandle, highCandle + Slippage.ValueInt * _tab.Securiti.PriceStep);

                _tab.CloseAtProfit(
                    openPositions[i], _lastPrice - (_lastPcUp - _lastPcDown),
                    (_lastPrice - (_lastPcUp - _lastPcDown)) + Slippage.ValueInt * _tab.Securiti.PriceStep);
            }
        }
    }
Esempio n. 4
0
        /// <summary>
        /// logic close position
        /// логика зыкрытия позиции
        /// </summary>
        private void LogicClosePosition()
        {
            List <Position> openPositions = _tab.PositionsOpenAll;

            for (int i = 0; openPositions != null && i < openPositions.Count; i++)
            {
                if (openPositions[i].State != PositionStateType.Open)
                {
                    continue;
                }
                List <decimal> ma     = _Ssma.DataSeries.ByName("Ma");
                decimal        lastma = ma[ma.Count - 1];
                if (openPositions[i].Direction == Side.Buy)
                {
                    decimal newfr = GetLastFractail(Fractail.DataSeries.ByName("SeriesDown"));
                    _tab.CloseAtTrailingStop(openPositions[i], newfr, newfr - Slipage.ValueDecimal);
                    _tab.CloseAtProfit(openPositions[i], lastma + Slipage.ValueDecimal, lastma);
                }
                else
                {
                    decimal newfr = GetLastFractail(Fractail.DataSeries.ByName("SeriesUp"));
                    _tab.CloseAtTrailingStop(openPositions[i], newfr, newfr + Slipage.ValueDecimal);
                    _tab.CloseAtProfit(openPositions[i], lastma - Slipage.ValueDecimal, lastma);
                }
            }
        }
Esempio n. 5
0
        private void TabOnPositionOpeningSuccesEvent(Position position)
        {
            decimal stopPrice             = 0;
            decimal stopActivationPrice   = 0;
            decimal profitPrice           = 0;
            decimal profitActivationPrice = 0;

            if (position.Direction == Side.Buy)
            {
                stopPrice             = position.EntryPrice - position.EntryPrice * (Stop.ValueDecimal / 100);
                stopActivationPrice   = stopPrice - stopPrice * (Slippage.ValueDecimal / 100);
                profitPrice           = position.EntryPrice + position.EntryPrice * (Profit.ValueDecimal / 100);
                profitActivationPrice = profitPrice - stopPrice * (Slippage.ValueDecimal / 100);
            }
            if (position.Direction == Side.Sell)
            {
                stopPrice             = position.EntryPrice + position.EntryPrice * (Stop.ValueDecimal / 100);
                stopActivationPrice   = stopPrice + stopPrice * (Slippage.ValueDecimal / 100);
                profitPrice           = position.EntryPrice - position.EntryPrice * (Profit.ValueDecimal / 100);
                profitActivationPrice = profitPrice + stopPrice * (Slippage.ValueDecimal / 100);
            }

            _tab.CloseAtStop(position, stopActivationPrice, stopPrice);
            _tab.CloseAtProfit(position, profitActivationPrice, profitPrice);
        }
Esempio n. 6
0
        public void TryReloadStopAndProfit(BotTabSimple bot, Position position)
        {
            if (StopIsOn)
            {
                if (position.Direction == Side.Buy)
                {
                    decimal priceRedLine = position.EntryPrice - GetStopDistance(position, bot.Securiti);
                    decimal priceOrder   = priceRedLine - GetStopSlippageDistance(position, bot.Securiti);

                    bot.CloseAtStop(position, priceRedLine, priceOrder);
                }

                if (position.Direction == Side.Sell)
                {
                    decimal priceRedLine = position.EntryPrice + GetStopDistance(position, bot.Securiti);
                    decimal priceOrder   = priceRedLine + GetStopSlippageDistance(position, bot.Securiti);

                    bot.CloseAtStop(position, priceRedLine, priceOrder);
                }
            }

            if (ProfitIsOn)
            {
                if (position.Direction == Side.Buy)
                {
                    decimal priceRedLine = position.EntryPrice + GetProfitDistance(position, bot.Securiti);
                    decimal priceOrder   = priceRedLine - GetProfitDistanceSlippage(position, bot.Securiti);

                    bot.CloseAtProfit(position, priceRedLine, priceOrder);
                }

                if (position.Direction == Side.Sell)
                {
                    decimal priceRedLine = position.EntryPrice - GetProfitDistance(position, bot.Securiti);
                    decimal priceOrder   = priceRedLine + GetProfitDistanceSlippage(position, bot.Securiti);

                    bot.CloseAtProfit(position, priceRedLine, priceOrder);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// closing logic
        /// логика закрытия позиции
        /// </summary>
        private void Strateg_ClosePosition(Position position)
        {
            List <Position> openPositions = _tab.PositionsOpenAll;

            for (int i = 0; openPositions != null && i < openPositions.Count; i++)
            {
                if (openPositions[i].Direction == Side.Buy)
                {
                    decimal heightPattern = Math.Abs(_tab.CandlesAll[_tab.CandlesAll.Count - 3].Open - _tab.CandlesAll[_tab.CandlesAll.Count - 1].Close);
                    decimal priceStop     = _lastPrice - (heightPattern * ProcHeightStop) / 100;
                    decimal priceTake     = _lastPrice + (heightPattern * ProcHeightTake) / 100;
                    _tab.CloseAtStop(openPositions[i], priceStop, priceStop - Slipage);
                    _tab.CloseAtProfit(openPositions[i], priceTake, priceTake - Slipage);
                }
                else
                {
                    decimal heightPattern = Math.Abs(_tab.CandlesAll[_tab.CandlesAll.Count - 1].Close - _tab.CandlesAll[_tab.CandlesAll.Count - 3].Open);
                    decimal priceStop     = _lastPrice + (heightPattern * ProcHeightStop) / 100;
                    decimal priceTake     = _lastPrice - (heightPattern * ProcHeightTake) / 100;
                    _tab.CloseAtStop(openPositions[i], priceStop, priceStop + Slipage);
                    _tab.CloseAtProfit(openPositions[i], priceTake, priceTake + Slipage);
                }
            }
        }
        private void ClosePosLogic(List <Candle> candles, Position pos)
        {
            if (pos.State != PositionStateType.Open)
            {
                return;
            }

            if (pos.StopOrderIsActiv == true ||
                pos.ProfitOrderIsActiv == true)
            {
                return;
            }

            decimal profitActivation = pos.EntryPrice + pos.EntryPrice * ProfitLenPercent.ValueDecimal / 100;

            _tab.CloseAtProfit(pos, profitActivation, profitActivation);

            decimal stopActivation = pos.EntryPrice - pos.EntryPrice * StopLenPercent.ValueDecimal / 100;

            _tab.CloseAtStop(pos, stopActivation, stopActivation);
        }