JBI

Strategy Backtest Kit

34
Strategy Backtest Kit. You have just to define your own entry / exit setups. The strategy I have coded into this is : BUY when MACD > 0 / SELL when MACD < 0. Always in position.
Follow JBI for his daily analyses!
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
study(title = "Strategy Backtest Kit", overlay = false)

/// PROGRAMMED BY JBI FOR TRADINGVIEW


percentual = input(true, title = "Percentual Income")
testlen = input(100, title = "Test Length")
show = input(true, title = "Show W/L ratio?")
// DEFINE ENTRY TO LONG POSITION
entryUP = ema(close, 12) > ema(close, 26)
// DEFINE ENTRY TO SHORT POSITION
entryDOWN = not entryUP

// DEFINE EXIT FROM LONG POSITION
exitUP = entryDOWN
// DEFINE EXIT FROM SHORT POSITION
exitDOWN = entryUP



///// Do not change this

entry1 = entryUP and not entryUP[1] ? 1 : 0
entry2 = entryDOWN and not entryDOWN[1] ? 1 : 0

exit1 = exitUP ? 1 : 0
exit2 = exitDOWN ? 1 : 0


up = entry1 ? close : exit1 and up[1] != -111 ? -111 : up[1]
down = entry2 ? close : exit2 and down[1] != -111 ? -111 : down[1]

output1 = exit1 and up[1] != -111 and percentual ? ((close - up[1]) / up[1]) : exit1 and up[1] != -111 and not percentual ? (close - up[1]) : 0
output2 = exit2 and down[1] != -111 and percentual ? ((down[1] - close) / down[1]) : exit2 and down[1] != -111 and not percentual ? (down[1] - close) : 0

otpt = output1 + output2

wlr = otpt != 0 and otpt > 0 ? 1 : 0


output = sum((otpt), testlen)
entries = sum((entry1 + entry2), testlen)
wlrf = sum((wlr), testlen)

///// Do not change this


wlrfinal = show ? wlrf / entries : na

plot(wlrfinal, title = "Percent of winning trades")
plot(output, title = "Brutto Income")