Skip to content

Instantly share code, notes, and snippets.

@subhanahmed047
Last active July 22, 2023 13:20
Show Gist options
  • Save subhanahmed047/901e74211617923c63f0259ce0539a42 to your computer and use it in GitHub Desktop.
Save subhanahmed047/901e74211617923c63f0259ce0539a42 to your computer and use it in GitHub Desktop.
[tradinghook] - Renko Trend Reversal Strategy
//@version=5
strategy(title='[tradinghook] - Renko Trend Reversal Strategy', shorttitle='[tradinghook] - Renko TRS', overlay=true)
// INPUTS
renkoATRLength = input.int(10, minval=1, title='ATR Length')
stopLossPct = input.float(1.0, title='Stop Loss Percentage', step=0.1)
takeProfitPct = input.float(2.0, title='Take Profit Percentage', step=0.1)
startDate = input.time(timestamp("01 Jan 2022 00:00"), title="Start Date")
endDate = input.time(timestamp("31 Dec 2022 23:59"), title="End Date")
// CALCULATION
param = ticker.renko(syminfo.tickerid, 'ATR', renkoATRLength)
var float stopLossPrice = na
var float takeProfitPrice = na
renkoClose = request.security(param, timeframe.period, close)
renkoOpen = request.security(param, timeframe.period, open)
buySignal = ta.crossunder(renkoOpen, renkoClose) and time >= startDate and time <= endDate
sellSignal = ta.crossover(renkoOpen, renkoClose) and time >= startDate and time <= endDate
colorGreen = #089981
colorRed = #F23645
col = renkoClose < renkoOpen ? colorRed : colorGreen
// PLOTS
plot(renkoOpen, title="Renko Open", style=plot.style_line, linewidth=2, color=col)
plotshape(buySignal, "Buy", shape.labelup, location.belowbar, colorGreen, 0, "Buy", color.white)
plotshape(sellSignal, "Sell", shape.labeldown, location.abovebar, colorRed, 0, "Sell", color.white)
if (buySignal)
stopLossPrice := renkoOpen * (1 - stopLossPct / 100)
takeProfitPrice := renkoOpen * (1 + takeProfitPct / 100)
strategy.entry("Long", strategy.long)
strategy.exit("ExitLong", "Long", stop = stopLossPrice, limit = takeProfitPrice, comment="SL: " + str.tostring(stopLossPrice) + "TP: " + str.tostring(takeProfitPrice))
if (sellSignal)
stopLossPrice := renkoOpen * (1 + stopLossPct / 100)
takeProfitPrice := renkoOpen * (1 - takeProfitPct / 100)
strategy.entry("Short", strategy.short)
strategy.exit("ExitShort", "Short", stop = stopLossPrice, limit = takeProfitPrice, comment="SL: " + str.tostring(stopLossPrice) + "TP: " + str.tostring(takeProfitPrice))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment