Strategy v5: improve backtest realism (entry-based SL/TP, combined exits, pyramiding=0, commission/slippage)

This commit is contained in:
root
2025-10-18 20:40:10 +02:00
parent 8ae4a9148a
commit d5c8b8b34a

View File

@@ -1,5 +1,17 @@
//@version=5
strategy("Bullmania Money Line Strategy v5", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
strategy(
"Bullmania Money Line Strategy v5",
overlay=true,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
initial_capital=10000,
pyramiding=0,
commission_type=strategy.commission.percent,
commission_value=0.1, // 0.1% commission per trade
slippage=1,
calc_on_order_fills=true,
calc_on_every_tick=false
)
// Parameter Mode
paramMode = input.string("Profiles by timeframe", "Parameter Mode", options=["Single", "Profiles by timeframe"], tooltip="Choose whether to use one global set of parameters or timeframe-specific profiles.")
@@ -121,14 +133,20 @@ if buyFlip and longOk
if sellFlip and shortOk
strategy.entry("Short", strategy.short)
// Exits
if useStopLoss
strategy.exit("Exit Long SL", "Long", stop=close * (1 - stopLossPct / 100))
strategy.exit("Exit Short SL", "Short", stop=close * (1 + stopLossPct / 100))
// Exits (based on entry price; combine SL/TP into a single exit per side)
// Long side
if strategy.position_size > 0
var string longExitId = "L-Exit"
longStop = useStopLoss ? strategy.position_avg_price * (1 - stopLossPct / 100.0) : na
longLimit = useTakeProfit ? strategy.position_avg_price * (1 + takeProfitPct / 100.0) : na
strategy.exit(longExitId, from_entry="Long", stop=longStop, limit=longLimit)
if useTakeProfit
strategy.exit("Exit Long TP", "Long", limit=close * (1 + takeProfitPct / 100))
strategy.exit("Exit Short TP", "Short", limit=close * (1 - takeProfitPct / 100))
// Short side
if strategy.position_size < 0
var string shortExitId = "S-Exit"
shortStop = useStopLoss ? strategy.position_avg_price * (1 + stopLossPct / 100.0) : na
shortLimit = useTakeProfit ? strategy.position_avg_price * (1 - takeProfitPct / 100.0) : na
strategy.exit(shortExitId, from_entry="Short", stop=shortStop, limit=shortLimit)
// Plot buy/sell signals
plotshape(buyFlip and longOk, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.circle, size=size.small)