Stoploss algorithm working on Candles, but not Renko

Created at 28 Jul 2021, 11:37
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!
WA

waym77

Joined 22.07.2021

Stoploss algorithm working on Candles, but not Renko
28 Jul 2021, 11:37


Hi all,

I have created a stop loss algorithm that works like this:

Initial Stop Loss = 11 pips on Execution.
Stop Loss Modified = Supertrend Last + 5 extra pips until the breakeven trigger
The breakeven trigger is 5 pips, at which point the stop is kept at breakeven for the rest of the position duration.

The algorithm works... but only on candles for some reason.

To visually explain this, I have attached some images:


 

 

 

 

 

 

 

 

 

 

 

In this image of a backtest I ran, you can see that this works exactly as intended. The breakeven requirement is never hit, thus the stop is equal to Supertrend Downtrend + 5 pips.

However, in this image:


 

This image comes from a demo running with the initial stop of 11 pips still intact. The red line is the actual exit at 11 pips, and the purple line is where the stop loss should have been.

Here is the logic for the stop loss:
 

if (ActiveBuy != null || ActiveSell != null)
            {
                var entryPrice = ActiveBuy != null ? ActiveBuy.EntryPrice : ActiveSell.EntryPrice;
                var sT_Stop = ActiveBuy != null ? _STrend.UpTrend.Last(1) : _STrend.DownTrend.Last(1);
                var distance = 0.0;
                var beTrigger = 5.0;
                var breakEven = ActiveBuy != null ? entryPrice + ExtraPips * Symbol.PipSize : entryPrice - ExtraPips * Symbol.PipSize;
                var _mod_SL = ActiveBuy != null ? sT_Stop + ExtraPipsStop * Symbol.PipSize : sT_Stop + ExtraPipsStop * Symbol.PipSize;

                if (ActiveBuy != null)
                {
                    distance = Symbol.Bid - entryPrice;
                    if (distance >= beTrigger * Symbol.PipSize && ActiveBuy.StopLoss != breakEven)
                    {
                        ModifyPosition(ActiveBuy, breakEven, null);
                    }
                    else if (ActiveBuy.StopLoss != _mod_SL && ActiveBuy.StopLoss != breakEven)
                    {
                        ModifyPosition(ActiveBuy, _mod_SL, null);
                    }
                }
                else if (ActiveSell != null)
                {
                    distance = entryPrice - Symbol.Ask;
                    if (distance >= beTrigger * Symbol.PipSize && ActiveSell.StopLoss != breakEven)
                    {
                        ModifyPosition(ActiveSell, breakEven, null);
                    }
                    else if (ActiveSell.StopLoss != _mod_SL && ActiveSell.StopLoss != breakEven)
                    {
                        ModifyPosition(ActiveSell, _mod_SL, null);
                    }
                }



Any advice would be greatly appreciated


@waym77
Replies

amusleh
28 Jul 2021, 14:48

Hi,

Can you post the cBot full code?


@amusleh

waym77
28 Jul 2021, 16:42

RE:

amusleh said:

Hi,

Can you post the cBot full code?

Hi,

 

Thanks for the reply, but it's not necessary. I set the stop at executing to null and it worked.

Sharing just in case someone has the same problem. 


@waym77