Stop Loss Not being set

Created at 06 Sep 2022, 15:58
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!
JA

jaydcrowe1989

Joined 11.08.2022

Stop Loss Not being set
06 Sep 2022, 15:58


Hi,

I have create a bot and when it determines it has a trade it will place a stop order passing in the Entry Price, Stop Loss Pips and Take Profit Pips. Sometimes when the trade gets triggered the stop loss is null and the trade is losing more than it should. Has anyone come across this before and knows how to stop it?

Cheers,

Jay


@jaydcrowe1989
Replies

PanagiotisCharalampous
06 Sep 2022, 16:12

Hi Jay,

This happens when the stop loss falls within the spread. The only solution is to check your positions after opening and handle the situation accordingly.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

jaydcrowe1989
06 Sep 2022, 16:30

RE:

PanagiotisCharalampous said:

Hi Jay,

This happens when the stop loss falls within the spread. The only solution is to check your positions after opening and handle the situation accordingly.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Thank you, that makes complete sense. I have noticed there is an overridable method that I can close the trade straight away if it gets triggered and the stop loss is null, so I will use this for now. It does say that this method is obsolete though?


@jaydcrowe1989

prosteel1
07 Sep 2022, 07:40 ( Updated at: 07 Sep 2022, 07:43 )

RE: RE:

jaydcrowe1989 said:

PanagiotisCharalampous said:

Hi Jay,

This happens when the stop loss falls within the spread. The only solution is to check your positions after opening and handle the situation accordingly.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Thank you, that makes complete sense. I have noticed there is an overridable method that I can close the trade straight away if it gets triggered and the stop loss is null, so I will use this for now. It does say that this method is obsolete though?

The sloploss and take profit can also be effected by slippage so I first correct for slippage, then for null stoploss and if still not set then close the position.

I store the stoploss etc in the comment  so I can have positions on multiple pairs. 

I don't get obsolete warnings with this.

protected override void OnStart()
        {
            Positions.Opened += PositionsOnOpened;
        }

private void PositionsOnOpened(PositionOpenedEventArgs args)
        {
            var pos = args.Position;
            if (pos.Comment != "" && pos.SymbolName == SymbolName)
            {
                var splitted = pos.Comment.Split(' ');
                int m = Convert.ToInt32(splitted[0]);
                int n = Convert.ToInt32(splitted[1]);
                double ep = Convert.ToDouble(splitted[2]);
                double ch = Convert.ToDouble(splitted[3]);
                double sl = Math.Round((Convert.ToDouble(splitted[4])), Symbol.Digits);
                double tp = Math.Round((Convert.ToDouble(splitted[5])), Symbol.Digits);
                if (pos.Label == "Long")
                    LongTradeSLPrice = sl;

                // Correct any slippage
                if (LongTRFPrice[m] > sl)
                    sl = LongTRFPrice[m];
                // Try to correct stoploss not being set correctly
                if (pos.StopLoss != sl)
                    ModifyPosition(pos, sl, tp);
                // If stoploss still not correct, close position
                if (pos.StopLoss != sl)
                    ClosePosition(pos);
            }

 


@prosteel1