// // 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 RSI", overlay=false, max_bars_back=5000) mode =input(title = "[SETUP] Method", defval = 'ATR', options=['Traditional', 'ATR']) modevalue = input(title ="[SETUP] Atr Period (ATR)", defval = 14, minval = 1) boxsize = input(title ="[SETUP] Brick Size (Traditional)", defval = 10.0, minval = 0.000000000000001) source =input(defval = "hl", title = "[SETUP] Source", options=['close', 'hl']) //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 // Renko RSI rsilen = input(2, title="[RSI] RSI Length", minval=1) rsiob = input(80, title="[RSI] RSI Overbought Level", minval=1, maxval = 100) rsios = input(20, title="[RSI] RSI Oversold Level", minval=1, maxval = 100) trcnt = 0 trcnt := change(icloseprice) ? 1 : nz(trcnt[1]) + 1 trcnt := trcnt > 4000 ? 4000 : trcnt float obox = na obox := change(icloseprice) ? nz(box[1]) : nz(obox[1]) trch = false trch := change(trend) and change(icloseprice) ? true : change(trend)==0 and change(icloseprice) ? false : nz(trch,false) Renko_rsi(ser, len)=> float res = na if nz(ser) != 0 and nz(ser[trcnt]) != 0 float rsup = na, float rsdn = na if change(ser) == 0 res := res[1] rsup := rsup[1] rsdn := rsdn[1] if change(ser) != 0 if abs(ser - ser[trcnt]) == obox u = max(ser - ser[trcnt], 0) // upward change d = max(ser[trcnt] - ser, 0) // downward change rsup := (u + (len - 1) * nz(rsup[trcnt])) / len rsdn := (d + (len - 1) * nz(rsdn[trcnt])) / len rs = rsup / rsdn res := rsdn == 0 ? 100 : 100 - 100 / (1 + rs) if abs(ser - ser[trcnt]) > obox bb = ser > ser[trcnt] ? obox : -obox u = trch ? max(bb*2, 0) : max(bb, 0) // upward change d = trch ? max(-bb*2, 0) : max(-bb, 0) // downward change rsup := (u + (len - 1) * nz(rsup[trcnt])) / len rsdn := (d + (len - 1) * nz(rsdn[trcnt])) / len ktsy = trch ? 3 : 2 cc = ser > nz(ser[trcnt]) ? nz(ser[trcnt]) + ktsy * obox : nz(ser[trcnt]) - ktsy * obox k = floor((abs(cc - ser) / obox)) k := k > 20 ? 20 : k loop = trch ? (trend == -1 and cc>=ser) or (trend == 1 and cc<=ser) ? true : false : true if loop for x = 0 to k u = max(bb, 0) // upward change d = max(-bb, 0) // downward change rsup := (u + (len - 1) * rsup) / len rsdn := (d + (len - 1) * rsdn) / len rs = rsup / rsdn res := rsdn == 0 ? 100 : 100 - 100 / (1 + rs) res h1 = hline(rsiob, title = "RSI Overbought Level", editable = false) h2 = hline(rsios, title = "RSI Oversold Level", editable = false) fill(h1, h2, color = color.blue, editable = false) Renkorsi = Renko_rsi(icloseprice, rsilen) plot(Renkorsi, linewidth = 2, color = color.blue, editable = false) alertcondition(Renkorsi < rsiob and nz(Renkorsi[1]) >= rsiob, title='Renko RSI moved below Overbought level', message='Renko RSI moved below Overbought level') alertcondition(Renkorsi > rsiob and nz(Renkorsi[1]) <= rsiob, title='Renko RSI moved above Overbought level', message='Renko RSI moved above Overbought level') alertcondition(Renkorsi < rsios and nz(Renkorsi[1]) >= rsios, title='Renko RSI moved below Oversold level', message='Renko RSI moved below Oversold level') alertcondition(Renkorsi > rsios and nz(Renkorsi[1]) <= rsios, title='Renko RSI moved above Oversold level', message='Renko RSI moved above Oversold level')