TakeProfit % and StopLoss %

Created at 17 Jan 2017, 18:14
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
OT

ottone.and

Joined 17.01.2017

TakeProfit % and StopLoss %
17 Jan 2017, 18:14


Hi

I need help for settin StopLoss% and TakeProfit%.My code not working:

 

private void ClosePosition(TradeType tradeType)
        {
            bool hasNeededPosition = Positions.Any(position => position.Label == StrategyLabel && position.TradeType == tradeType);
            if (!hasNeededPosition)
            {
                double SLpips = MarketSeries.Close.LastValue * StopLossPcnt * 0.01 / Symbol.TickSize;
                double TPpips = MarketSeries.Close.LastValue * TakeProfitPcnt * 0.01 / Symbol.TickSize;
                ExecuteMarketOrder(tradeType, Symbol, (long)Volume, StrategyLabel, SLpips, TPpips);
            }
        }




        private void OpenPosition(TradeType tradeType)
        {
            foreach (var position in Positions)
            {
                if (position.Label == StrategyLabel && position.TradeType == tradeType)
                {
                    //Trade.Close(position);
                    ClosePosition(position);
                }
            }
        }

        protected override void OnPositionOpened(Position openedPosition)
        {
            position = openedPosition;
        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}


@ottone.and