JBI

Strategy Backtest Kit

393 2 27
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!
Remove from Favorite Scripts Add to Favorite Scripts
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")

JBI
2 years ago
EDIT: To percentual, you have to (output * 100) - so this code:



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 : 0
entry2 = entryDOWN and not entryDOWN ? 1 : 0

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


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

output1 = exit1 and up != -111 and percentual ? (((close - up) / up) * 100) : exit1 and up != -111 and not percentual ? (close - up) : 0
output2 = exit2 and down != -111 and percentual ? (((down - close) / down) * 100) : exit2 and down != -111 and not percentual ? (down - 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")

Reply
MohanEdikuda
2 years ago
Hi JBI
How do you use this indicator ?
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out