#input BrickSize = 1.25;
input BrickTicks = 10.0;
#def BrickTicks = reference ATR();
input label = Yes;
def BrickSize = BrickTicks * TickSize();
def Mortar = CompoundValue(1, if close() > Mortar[1] + BrickSize
then Mortar[1] + BrickSize
else if close() < Mortar[1] - BrickSize then Mortar[1] - BrickSize else Mortar[1] , close());
def Stack = if Mortar != Mortar[1] then Mortar[1] else Stack[1];
def mortarext = if IsNaN(close) then mortarext[1] else Mortar;
def stackext = if IsNaN(close) then stackext[1] else Stack;
plot Bricks = Mortar; plot Renko = Stack;
#plot Bricksext = mortarext;
#plot Renkoext = stackext;
input showcloud = yes;
def same=if same[1]==0 and bricks>bricks[1] and bricks>renko[1] then 1 else if same[1]==1 and max(renko,bricks)>=max(renko[1],bricks[1]) then 1 else 0;
def s1= if isnan(close) then s1[1] else same;
def s=s1;
defineglobalColor("UP", color.green);
defineglobalcolor("DN", color.red);
addcloud(if showcloud and s==1 then bricks else double.nan, renko, globalcolor("UP"),globalcolor("UP"));
addcloud(if showcloud and s==0 then renko else double.nan, bricks, globalcolor("DN"),globalcolor("DN"));
plot stoploss = if !isnan(close) then double.nan else if s==0 then max(mortarext,stackext) + ticksize() else min(mortarext,stackext) - ticksize();
#Bricks.AssignValueColor(if Bricks > Renko then Color.green else Color.red);
Bricks.AssignValueColor(if s==1 then Color.green else Color.red);
Renko.AssignValueColor(if s==1 then Color.green else Color.red);
#Bricksext.AssignValueColor(if (Bricksext) > (Renkoext) then Color.GREEN else Color.RED);
#Renkoext.AssignValueColor(if (Bricksext) > (Renkoext) then Color.GREEN else Color.RED);
AddLabel(label, "Renko: " + BrickSize, if Bricks > Renko then Color.GREEN else Color.RED);
input pricecolor = no;
AssignPriceColor(if pricecolor == no then Color.CURRENT else if s==1 then Color.green else Color.red);