input offset = 0;
input type = {default candle, heikenashi};
def h;
def l;
def o;
def c;
def r;
switch (type){
case candle:
h = high;
l = low;
o = open;
c = close;
r = h - l;
case heikenashi:
c = ohlc4;
o = CompoundValue(1, (o[1] + c[1]) / 2, (open[1] + close[1]) / 2);
h = Max(Max(high, o), c);
l = Min(Min(low, o), c);
r = h - l;
}
def HAclose = ohlc4;
def HAopen = CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (o[1] + c[1]) / 2);
def haopen_ = if haopen>haclose then HAopen + 0 else double.nan;
def HAhigh = if haopen>haclose then Max(Max(h, HAopen), HAclose) else double.nan;
def HAlow = if haopen>haclose then Min(Min(l, HAopen), HAclose) else double.nan;
def lastopen = if IsNaN(close[-1]) and !IsNaN(close) then o[offset] else lastopen[1];
def lasthigh = if IsNaN(close[-1]) and !IsNaN(close) then h[offset] else lasthigh[1];
def lastclose = if IsNaN(close[-1]) and !IsNaN(close) then c[offset] else lastclose[1];
def lastlow = if IsNaN(close[-1]) and !IsNaN(close) then l[offset] else lastlow[1];
input showlines = yes;
plot lopen = if !showlines then Double.NaN else lastopen;
plot lhigh = if !showlines then Double.NaN else lasthigh;
plot lclose = if !showlines then Double.NaN else lastclose;
plot llow = if !showlines then Double.NaN else lastlow;
lopen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lclose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
llow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lhigh.SetDefaultColor(Color.GREEN);
lclose.SetDefaultColor(Color.YELLOW);
llow.SetDefaultColor(Color.RED);
input showlabels = yes;
AddLabel(showlabels, "O: " + AsText(lastopen), Color.white);
AddLabel(showlabels, "H: " + AsText(lasthigh), Color.GREEN);
AddLabel(showlabels, "L: " + AsText(lastlow), Color.RED);
AddLabel(showlabels, "C: " + AsText(lastclose), Color.YELLOW);
AddLabel(showlabels, "R: " + AsText(h[offset]-l[offset]), Color.cyan);
input showbubbles = yes;
input bubblemover = 3;
def b = bubblemover;
def b1 = b + 1;
def last = IsNaN(close[b]) and !IsNaN(close[b1]);
AddChartBubble(showbubbles and last, lopen, "O: " + AsText(lastopen), Color.white);
AddChartBubble(showbubbles and last, lhigh, "H: " + AsText(lasthigh), Color.GREEN);
AddChartBubble(showbubbles and last, lclose, "C: " + AsText(lastclose), Color.YELLOW);
AddChartBubble(showbubbles and last, llow, "L: " + AsText(lastlow), Color.RED, up = No);