Professional Documents
Culture Documents
Aaa
Aaa
// 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
study("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")
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 == -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
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)
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
botrend = 0
botrend := setA == 1 ? 1 : setB == 1 ? -1 : nz(botrend[1])
// Trend
showtrend = input(true, title="Show Trend")
showtrhold = input(true, title="Show Threshold")
tremalen = input(defval = 34, title="Trend EMA Length", minval = 1)
barcountwhip = input(defval = 3, title="Wait # Bars for Reversal", minval = 0)
thsreversal = input(defval = 3.0, title="Trend Threshold", minval = 0, step = 0.1)
thsreversal2 = input(defval = 1.5, title="Trend Threshold for Reversal", minval =
0, step = 0.1)
trcnt1 = 0
trcnt1 := change(icloseprice) ? 1 : nz(trcnt1[1]) + 1
trcnt1 := trcnt1 > 4000 ? 4000 : trcnt1
countch = 0
countch := change(icloseprice) ? nz(countch[1]) + 1 : nz(countch[1])
trch = false
trch := change(trend) and change(icloseprice) ? true : change(trend)==0 and
change(icloseprice) ? false : nz(trch,false)
float tema = na
float obox = na
obox := change(icloseprice) != 0 ? nz(box[1]) : nz(obox[1])
tmp = myema(icloseprice, tremalen, trcnt1, obox)
tema := icloseprice - floor((icloseprice - tmp) / obox) * obox
if waitit > 0
mtrend := nz(mtrend[1])
if waitit > barcountwhip
if mtrend == 1
if icloseprice >= TrendUp + thsreversal2 * box
waitit := 0
if icloseprice <= TrendUp - thsreversal2 * box
waitit := 0
mtrend := -1
TrendDown:= icloseprice[1] < TrendDown[1] ? min(Dnt, TrendDown[1]) :
Dnt
else
if icloseprice <= TrendDown - thsreversal2 * box
waitit := 0
if icloseprice >= TrendDown + thsreversal2 * box
waitit := 0
mtrend := 1
TrendUp := icloseprice[1] > TrendUp[1] ? max(Upt, TrendUp[1]) : Upt
trendline = plot(Tsl, linewidth = 3, color = showtrend and Tsl !=0 and nz(Tsl[1]) !
=0 ? trendcol : na, transp = 0, editable = false)
trcol = showtrend and showtrhold and mtrend == nz(mtrend[1]) and Tsl !=0 and
nz(Tsl[1]) !=0 ? waitit == 0 ? mtrend == 1 ? color.new(color.lime, 80) :
color.new(color.red, 80) : color.new(color.yellow, 80) : color.new(color.white,
100)
trcol1 = showtrend and showtrhold and Tsl !=0 and nz(Tsl[1]) !=0 ?
color.new(color.gray, 30) : color.new(color.white, 100)
trline = plot(Tsl2, linewidth = 1, style = plot.style_circles, color = na, editable
= false)
fill(trendline, trline, color =trcol, editable = false)