Description //@version=2 study("Renko Reversal alert", overlay=true) //Buy entry if a bearish renko brick is followed by a bullish brick //Sell entry if a bullish brick is followed by a bearish brick long = close > open[1] and close[1] < open[2] short = close < open[1] and close[1] > open[2] //Use these alerts to create server-side alerts (right-click on one of the buy or sell arrows on the chart and choose "add alert") alertcondition(long, title='Long opportunity', message='Renko reversal') alertcondition(short, title='Short opportunity', message='Renko reversal') //Use this to customize the look of the arrows to suit your needs. plotshape(long, location=location.belowbar, color=lime, style=shape.arrowup, text="Buy") plotshape(short, location=location.abovebar, color=red, style=shape.arrowdown, text="Sell") //@version=5 indicator('Renko', max_bars_back=5000) get_renko(box_size) => var float base_price = input(title='Base price', defval=close) var float r_open = base_price - box_size var float r_close = close var int up_list = 0 var int down_list = 0 var int up_move = 0 var int down_move = 0 var int built_bricks_up = 0 var int built_bricks_down = 0 var int counter_up_series = 0 var int counter_down_series = 0 var int required_series_up = 0 var int required_series_down = 0 var int required_bricks_up = 0 var int required_bricks_down = 0 var bool b_up_list = false var bool b_down_list = false var bool b_up_move = false var bool b_down_move = false var bool in_the_range_up = false var bool in_the_range_down = false var int up_stop_index = 0 var int down_stop_index = 0 var int up_temporary_index = 0 var int down_temporary_index = 0 // creating lists if bar_index > 0 if close > open down_move := 0 if b_up_list up_move := int((close - base_price) / box_size) if up_move > up_list up_list := up_move down_list := na else if b_down_list up_move := int((close - (base_price - down_list * box_size)) / box_size) else down_list := na else if close < open up_move := 0 if b_down_list down_move := int((base_price - close) / box_size) if down_move > down_list down_list := down_move up_list := na else if b_up_list down_move := int((base_price + up_list * box_size - close) / box_size) else down_list := na up_list := na if b_up_list and down_move >= 2 base_price += (up_list - 1) * box_size b_up_list := false up_list := na b_down_list := true down_list := down_move - 1 else if b_down_list and up_move >= 2 base_price -= (down_list - 1) * box_size b_down_list := false down_list := na b_up_list := true up_list := up_move - 1 if not b_up_list and not b_down_list up_move := int((close - base_price) / box_size) down_move := int((base_price - close) / box_size) if up_move > 0 down_move := 0 b_up_list := true b_up_move := true up_list := up_move down_list := na else if down_move > 0 up_move := 0 b_down_list := true b_down_move := true down_list := down_move up_list := na else up_list := na down_list := na r_close := na // creating open and close series if b_up_move for i = 0 to bar_index - up_stop_index - 1 by 1 if not na(up_list[i]) and na(up_list[i + 1]) counter_up_series += 1 required_bricks_up := up_list[i] required_bricks_up if i == bar_index - up_stop_index - 1 for j = i to 0 by 1 up_temporary_index := bar_index[j] required_bricks_up := up_list[j] if j == 0 break if not na(up_list[j]) and na(up_list[j - 1]) up_temporary_index := bar_index[j - 1] break break if counter_up_series == 1 and not na(up_list[0]) in_the_range_up := true counter_up_series := 0 if built_bricks_up < required_bricks_up r_open += box_size r_close := r_open + box_size built_bricks_up += 1 else if in_the_range_up and built_bricks_up == required_bricks_up r_close := na else up_stop_index := up_temporary_index built_bricks_up := 0 built_bricks_down := 1 b_up_move := false b_down_move := true r_close := r_open - box_size in_the_range_up := false else if b_down_move for i = 0 to bar_index - down_stop_index - 1 by 1 if not na(down_list[i]) and na(down_list[i + 1]) counter_down_series += 1 required_bricks_down := down_list[i] if i == bar_index - down_stop_index - 1 for j = i to 0 by 1 down_temporary_index := bar_index[j] required_bricks_down := down_list[j] if j == 0 break if not na(down_list[j]) and na(down_list[j - 1]) down_temporary_index := bar_index[j - 1] break break if counter_down_series == 1 and not na(down_list[0]) in_the_range_down := true counter_down_series := 0 if built_bricks_down < required_bricks_down if up_stop_index == 0 and down_stop_index == 0 and built_bricks_down == 0 r_open += box_size r_close := r_open - box_size built_bricks_down += 1 else r_open -= box_size r_close := r_open - box_size built_bricks_down += 1 else if in_the_range_down and built_bricks_down == required_bricks_down r_close := na else down_stop_index := down_temporary_index built_bricks_down := 0 built_bricks_up := 1 b_down_move := false b_up_move := true r_close := r_open + box_size in_the_range_down := false else r_close := na [r_open, r_open > r_close ? r_open : r_close, r_open < r_close ? r_open : r_close, r_close] [r_open, r_high, r_low, r_close] = get_renko(input.float(defval=200.0, title='Box size', minval=0.00000001)) plotcandle(r_open, r_high, r_low, r_close, color=r_close > r_open ? color.green : color.red)