Smaller stop loss than expected

Created at 04 Mar 2024, 17:16
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!
FL

flappiyt

Joined 04.03.2024

Smaller stop loss than expected
04 Mar 2024, 17:16


Hello, I have a problem: my bot is setting smaller stop losses than expected. For example, the stop loss should be 12 pips below the close of a candle, but the bot sets it at 3.4 pips below. I have no idea what the problem is, but I imagine it has to do with when to use the addition (+) and subtraction (-) in the calculation of a stop loss.

 

[Parameter("Initial Stop Loss", DefaultValue = 10)]
        public double SL { get; set; }

protected override void OnBarClosed()
        {
            
            MarketSeries series = MarketData.GetSeries(TimeFrame);
            
            // Uzyskaj dane o ostatniej świeczce
                double open = series.Open.LastValue;
                double close = series.Close.LastValue;
                double low = series.Low.LastValue;
                double bodySize = Math.Abs(open - close);

                // Sprawdź kolor świeczki
                bool isBullish = close > open;

                // Ustaw stop loss zgodnie z warunkiem
                double stopLoss;

                double candleBodySize = Math.Abs(MarketSeries.Close[index] - MarketSeries.Open[index]);

                if (isBullish)
                {
                    if (bodySize < 10 * Symbol.PipSize)
                    {
                        stopLoss = close - SL * Symbol.PipSize;
                    }
                    else
                    {
                        stopLoss = open - SL * Symbol.PipSize;
                    }
                }
                else
                {
                    if (low - close <= 10 * Symbol.PipSize)
                    {
                        stopLoss = close + SL * Symbol.PipSize;
                    }
                    else
                    {
                        stopLoss = low - 10 * Symbol.PipSize + SL * Symbol.PipSize;
                    }
                }

                // Execute market order only when the conditions are met
                ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, "Frann", SL, TP);
                isAlreadyInTrade = true;
            
        }


@flappiyt
Replies

PanagiotisCharalampous
05 Mar 2024, 06:46

Hi there,

SL and TP should be set in pips. You seem to pass absolute prices instead.

Best regards,

Panagiotis


@PanagiotisCharalampous

firemyst
08 Mar 2024, 01:49

RE: Smaller stop loss than expected

PanagiotisCharalampous said: 

Hi there,

SL and TP should be set in pips. You seem to pass absolute prices instead.

Best regards,

Panagiotis

Where does he set the SL as a price instead of pips? 

The variable “SL” is set as a parameter and when he opens a position, that's what he passes:

ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume, "Frann", SL, TP);

“SL” isn't changed in the code he's provided.

Also, the “TP” is never set in the code posted either.

 


@firemyst