Stoploss algorithm working on Candles, but not Renko
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
amusleh
28 Jul 2021, 14:48
Hi,
Can you post the cBot full code?
@amusleh