Strategy v5: improve backtest realism (entry-based SL/TP, combined exits, pyramiding=0, commission/slippage)
This commit is contained in:
@@ -1,5 +1,17 @@
|
|||||||
//@version=5
|
//@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
|
// 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.")
|
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
|
if sellFlip and shortOk
|
||||||
strategy.entry("Short", strategy.short)
|
strategy.entry("Short", strategy.short)
|
||||||
|
|
||||||
// Exits
|
// Exits (based on entry price; combine SL/TP into a single exit per side)
|
||||||
if useStopLoss
|
// Long side
|
||||||
strategy.exit("Exit Long SL", "Long", stop=close * (1 - stopLossPct / 100))
|
if strategy.position_size > 0
|
||||||
strategy.exit("Exit Short SL", "Short", stop=close * (1 + stopLossPct / 100))
|
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
|
// Short side
|
||||||
strategy.exit("Exit Long TP", "Long", limit=close * (1 + takeProfitPct / 100))
|
if strategy.position_size < 0
|
||||||
strategy.exit("Exit Short TP", "Short", limit=close * (1 - takeProfitPct / 100))
|
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
|
// Plot buy/sell signals
|
||||||
plotshape(buyFlip and longOk, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.circle, size=size.small)
|
plotshape(buyFlip and longOk, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.circle, size=size.small)
|
||||||
|
|||||||
Reference in New Issue
Block a user