Stop Loss/ Take Profit being set at wrong distance by algo

Created at 25 Feb 2025, 06:42
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!
MI

michaelkearney213

Joined 06.11.2022

Stop Loss/ Take Profit being set at wrong distance by algo
25 Feb 2025, 06:42


Hi,

 

I'm having trouble getting it to set SL and TP at correct distance.

I set the deafult values

        [Parameter("Volume (Lots)", DefaultValue = 1)]
        public double VolumeInLots { get; set; }

        [Parameter("Stop Loss (Pips)", DefaultValue = 50, MaxValue = 10000, MinValue = 1, Step = 1)]
        public double StopLossInPips { get; set; }

        [Parameter("Take Profit (Pips)", DefaultValue = 100, MaxValue = 10000, MinValue = 1, Step = 1)]
        public double TakeProfitInPips { get; set; }

 

And then i get it to add SL/TP as part of the execute, but it is setting it always it to somewhere around 2500 pips when i am testing this on XAUUSD. Even if i change the default when i load a new instance

                            // Calculate TakeProfit and StopLoss based on pips and pip size
                            var takeProfitPrice = Symbol.Bid + (TakeProfitInPips * Symbol.PipSize);
                            var stopLossPrice = Symbol.Bid - (StopLossInPips * Symbol.PipSize);

                            // Execute market order with calculated take profit and stop loss
                            ExecuteMarketOrder(TradeType.Buy, Symbol.Name, VolumeInLots, Label, stopLossPrice, takeProfitPrice);


@michaelkearney213
Replies

firemyst
26 Feb 2025, 01:58

What does it print when you add the following lines before the ExecuteMarketOrder statement?

Print("TP {0} + ( {1} * {2} ) = {3} ", Symbol.Bid, TakeProfitInPips, Symbol.PipSize, Symbol.Bid + (TakeProfitInPips * Symbol.PipSize) )

Print("SL {0} - ( {1} * {2} ) = {3} ", Symbol.Bid, StopLossInPips, Symbol.PipSize, Symbol.Bid + (StopLossInPips * Symbol.PipSize) )

 

Then after the ExecuteMarketOrder statement, find the position and print the SL and TP values to confirm they've been set as expected.

 

Show us a screen capture showing the before and after values from the logging. Let's see what they say.

 

 


@firemyst