0% found this document useful (0 votes)
198 views

Renko Chart - Strategy

Easier to follow with trend ribbon. More accurate trading with advanced buy and sell signals. No more repaints thanks to AI-supported coding.

Uploaded by

moleno56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
198 views

Renko Chart - Strategy

Easier to follow with trend ribbon. More accurate trading with advanced buy and sell signals. No more repaints thanks to AI-supported coding.

Uploaded by

moleno56
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

//

// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © LonesomeTheBlue
//
//@version=4
strategy("Renko Chart", overlay=true, max_bars_back = 4900)
mode =input(title = "Method", defval = 'ATR', options=['Traditional', 'ATR'])
modevalue = input(title ="[ATR] Atr Period", defval = 14, minval = 1)
boxsize = input(title ="[Traditional] Brick Size", defval = 10.0, minval =
0.000000000000001)
source =input(defval = "hl", title = "Source", options=['close', 'hl'])
showstyle =input(title = "Chart Style As", defval = 'Area', options=['Candle',
'Area', 'Dont Show'])
breakoutcolor = input(defval = 'Blue/Red', title = "Color Theme", options
=['Green/Red', 'Yellow/Blue', 'White/Yellow', 'Orange/Blue', 'Lime/Red',
'Blue/Red'])
changebarcol = input(true, title = "Change Bar Colors")

//calc atr val


conv_atr(valu)=>
a = 0
num = syminfo.mintick
s = valu
if na(s)
s := syminfo.mintick
if num < 1
for i = 1 to 20
num := num * 10
if num > 1
break
a := a +1
for x = 1 to a
s := s * 10
s := round(s)
for x = 1 to a
s := s / 10
s := s < syminfo.mintick ? syminfo.mintick : s
s

//ATR box size calculation


atrboxsize = conv_atr(atr(modevalue))

float box = na
box := na(box[1]) ? mode == 'ATR' ? atrboxsize : boxsize : box[1]

reversal = 2
top = 0.0, bottom = 0.0
trend = 0
trend := barstate.isfirst ? 0 : nz(trend[1])
currentprice = 0.0
currentprice := source == 'close' ? close : trend == 1 ? high : low
float beginprice = na
beginprice := barstate.isfirst ? floor(open / box) * box : nz(beginprice[1])
iopenprice = 0.0
icloseprice = 0.0

if trend == 0 and box * reversal <= abs(beginprice - currentprice)


if beginprice > currentprice
numcell = floor(abs(beginprice - currentprice) / box)
iopenprice := beginprice
icloseprice := beginprice - numcell * box
trend := -1
if beginprice < currentprice
numcell = floor(abs(beginprice - currentprice) / box)
iopenprice := beginprice
icloseprice := beginprice + numcell * box
trend := 1

if trend == -1
nok = true
if beginprice > currentprice and box <= abs(beginprice - currentprice)
numcell = floor(abs(beginprice - currentprice) / box)
icloseprice := beginprice - numcell * box
trend := -1
beginprice := icloseprice
nok := false
else
iopenprice := iopenprice == 0 ? nz(iopenprice[1]) : iopenprice
icloseprice := icloseprice == 0 ? nz(icloseprice[1]) : icloseprice

tempcurrentprice = source == 'close' ? close : high


if beginprice < tempcurrentprice and box * reversal <= abs(beginprice -
tempcurrentprice) and nok //new column
numcell = floor(abs(beginprice - tempcurrentprice) / box)
iopenprice := beginprice + box
icloseprice := beginprice + numcell * box
trend := 1
beginprice := icloseprice
else
iopenprice := iopenprice == 0 ? nz(iopenprice[1]) : iopenprice
icloseprice := icloseprice == 0 ? nz(icloseprice[1]) : icloseprice
else
if trend == 1
nok = true
if beginprice < currentprice and box <= abs(beginprice - currentprice)
numcell = floor(abs(beginprice - currentprice) / box)
icloseprice := beginprice + numcell * box
trend := 1
beginprice := icloseprice
nok := false
else
iopenprice := iopenprice == 0 ? nz(iopenprice[1]) : iopenprice
icloseprice := icloseprice == 0 ? nz(icloseprice[1]) : icloseprice

tempcurrentprice = source == 'close' ? close : low


if beginprice > tempcurrentprice and box * reversal <= abs(beginprice -
tempcurrentprice) and nok //new column
numcell = floor(abs(beginprice - tempcurrentprice) / box)
iopenprice := beginprice - box
icloseprice := beginprice - numcell * box
trend := -1
beginprice := icloseprice
else
iopenprice := iopenprice == 0 ? nz(iopenprice[1]) : iopenprice
icloseprice := icloseprice == 0 ? nz(icloseprice[1]) : icloseprice
//if icloseprice changed then recalculate box size
box := change(icloseprice) ? mode == 'ATR' ? atrboxsize : boxsize : box

upcolor = breakoutcolor == 'Green/Red' ? color.green : breakoutcolor ==


'White/Yellow' ? color.white : breakoutcolor == 'Lime/Red' ? color.lime :
breakoutcolor == 'Blue/Red' ? color.blue : breakoutcolor == 'Yellow/Blue' ?
color.yellow : color.orange
downcolor = breakoutcolor == 'Yellow/Blue' or breakoutcolor == 'Orange/Blue' ?
color.blue : breakoutcolor == 'Green/Red' or breakoutcolor == 'Lime/Red' or
breakoutcolor == 'Blue/Red'? color.red : color.yellow

oprice =
trend == 1 ? nz(trend[1]) == 1 ? nz(icloseprice[1]) - nz(box[1]) :
nz(icloseprice[1]) + nz(box[1]) :
trend == -1 ? nz(trend[1]) == -1 ? nz(icloseprice[1]) + nz(box[1]) :
nz(icloseprice[1]) - nz(box[1]) :
nz(icloseprice[1])
oprice := oprice < 0 ? 0 : oprice

openline = plot(showstyle == 'Area' and oprice > 0? oprice : na, title = "Renko
Open", color = oprice < 0 or oprice[1] < 0 ? na : color.gray, editable = false)
closeline = plot(showstyle == 'Area' and icloseprice > 0 ? icloseprice : na, title
= "Renko Close", color = icloseprice <= 0 or icloseprice[1] <= 0 ? na : color.gray,
editable = false)
fill(openline, closeline, color = oprice <= 0 and icloseprice <=0 ? na : trend == 1
? upcolor : downcolor, transp = 70, editable = false)
plotcandle(showstyle == 'Candle' ? oprice : na, showstyle == 'Candle' ? max(oprice,
icloseprice) : na, showstyle == 'Candle' ? min(oprice , icloseprice) : na,
showstyle == 'Candle'? icloseprice : na, title='Renko Candles', color = trend ==
1 ? upcolor : downcolor, editable = false)

barcolor(changebarcol ? trend == 1 ? upcolor : downcolor : na, editable = false)

//keep last close/open price


float lasticloseprice = na
lasticloseprice := change(icloseprice) ? icloseprice[1] : nz(lasticloseprice[1])

// keep old columns


float chigh = na
float clow = na
ctrend = 0
chigh := change(trend) ? max(iopenprice[1], icloseprice[1]) : na
clow := change(trend) ? min(iopenprice[1], icloseprice[1]) : na
ctrend := change(trend) ? trend[1] : na

// ============== breakout strategy ============== added by user request


Length = input(title = "Length for Breakout", type = input.integer, minval = 1,
defval = 1)
showbreakout = input(title = "Show Breakout Trend", defval = true)

f_Brickhigh()=>
_ret = false
if trend == 1
_l = floor((icloseprice - iopenprice) / box) - 1
_ret := true
if _l < Length
for x = 0 to 3000
if na(trend[x+1])
_ret := false
break
if trend[x] != trend[x+1]
if trend[x+1] == 1
if icloseprice[x+1] >= icloseprice
_ret := false
break
_l := _l + (floor((icloseprice[x+1] - iopenprice[x+1]) /
box[x+1]))

if trend[x+1] == -1
start = icloseprice[x+1] + box[x+1]
forlen = floor((iopenprice[x+1] - icloseprice[x+1]) / box)
- 1
for i = 0 to forlen
if start < icloseprice
_l := _l + 1
start := start + box[x+1]
if _l >= Length
_ret := true
break
_ret

f_Bricklow()=>
_ret = false
if trend == -1
_l = floor((iopenprice - icloseprice) / box) - 1
_ret := true
if _l < Length
for x = 0 to 3000
if na(trend[x+1])
_ret := false
break
if trend[x] != trend[x+1]
if trend[x+1] == -1
if icloseprice[x+1] <= icloseprice
_ret := false
break
_l := _l + (floor((iopenprice[x+1] - icloseprice[x+1]) /
box[x+1]))

if trend[x+1] == 1
start = icloseprice[x+1] - box[x+1]
forlen = floor((icloseprice[x+1] - iopenprice[x+1]) / box)
- 1
for i = 0 to forlen
if start > icloseprice
_l := _l + 1
start := start - box[x+1]
if _l >= Length
_ret := true
break
_ret

Brickhigh = f_Brickhigh()
Bricklow = f_Bricklow()

switch = 0
setA = 0
setB = 0

if Brickhigh and switch[1] == 0


switch := 1
setA := 1
setB := 0
setB
else
if Bricklow and switch[1] == 1
switch := 0
setA := 0
setB := 1
setB
else
switch := nz(switch[1], 0)
setA := 0
setB := 0
setB

botrend = 0
botrend := setA == 1 ? 1 : setB == 1 ? -1 : nz(botrend[1])

boline = showbreakout ? botrend == 1 ? trend == 1 ? icloseprice : oprice : trend


== 1 ? oprice : icloseprice : na

//plot(boline, title = "Renko breakout", color = showbreakout ? botrend == 1 ?


color.lime : botrend == -1 ? color.red : na : na, linewidth = 3, editable = false,
transp = 0)
//alertcondition(setA == 1, title='Breakout Uptrend started', message='Breakout
Uptrend started')
//alertcondition(setB == 1, title='Breakout Downtrend started', message='Breakout
Downtrend started')

// Define entry condition


buy_condition = crossover(setA, 0)
sell_condition = crossover(setB, 0)

// Define exit condition


exit_condition = botrend == 0

// Strategy entry and exit


strategy.entry("Buy", strategy.long, when=buy_condition)
strategy.entry("Sell", strategy.short, when=sell_condition)

strategy.close("Buy", when=exit_condition)
strategy.close("Sell", when=exit_condition)

// Plot breakout line


plot(boline, title="Renko breakout", color=showbreakout ? botrend == 1 ? color.lime
: botrend == -1 ? color.red : na : na, linewidth=3, editable=false, transp=0)

// Alerts
alertcondition(setA == 1, title='Breakout Uptrend started', message='Breakout
Uptrend started')
alertcondition(setB == 1, title='Breakout Downtrend started', message='Breakout
Downtrend started')

You might also like