# k_line_bars_01
#https://usethinkscript.com/threads/is-it-possible-to-redraw-k-line-based-on-high-low-only.9761/
#Is it possible to redraw k-line based on High/Low only?
def bn = BarNumber();
def na = double.nan;
# look for engulfing
# check if big bar is up or down
def bardir = if close > open then 1 else if open > close then -1 else 0;
def engulf2 = if (high > high[-1] and low < low[-1]) then 1 else 0;
# if 3 bars make up 2 engulfing patterns, disable the 1st pair
def engulf = if engulf2[-1] then 0 else engulf2;
# k bar , combine hi and low from 2 engulfing bars,
# if up engulf , big bar high and small bar low
# if down engulf , big bar low and small bar high
# calc a new bar to draw over the small bar
# it will extend in the direction of big bar
def smalltop = if (engulf[1] and bardir[1] == 1) then high[1]
else if (engulf[1] and bardir[1] == -1) then high
else na;
def smallbot = if (engulf[1] and bardir[1] == 1) then low
else if (engulf[1] and bardir[1] == -1) then low[1]
else na;
input show_solid_blue_bars = yes;
def kh = smalltop;
def kl = smallbot;
# hollow blue bars
#def ko = kl;
#def kc = kh;
# solid blue bars
#def ko = kh;
#def kc = kl;
def ko = if show_solid_blue_bars then kh else kl;
def kc = if show_solid_blue_bars then kl else kh;
#------------------------------
# draw blue bar over the small enguled candle
def o;
def h;
def l;
def c;
o = ko;
h = kh;
l = kl;
c = kc;
AddChart(high = h, low = l, open = o, close = c, growcolor = color.cyan, fallcolor = color.yellow, type = ChartType.CANDLE);
#------------------------------
# draw a black bar over big engulfing bar , to make it disappear
input black_out_big_engulfing_bar = yes;
def bh;
def bl;
def bo;
def bc;
if black_out_big_engulfing_bar and engulf then {
bh = high;
bl = low;
bo = high;
bc = low;
} else {
bh = na;
bl = na;
bo = na;
bc = na;
}
AddChart(high = bh, low = bl, open = bo, close = bc, growcolor = color.black, fallcolor = color.yellow, type = ChartType.CANDLE);
#------------------------------
# test stuff
input show_engulfing_arrows1 = no;
# put arrow on small bar of engulfing
plot smallup = if (show_engulfing_arrows1 and engulf[1] and bardir[1] == 1) then low*0.994 else na;
smallup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
smallup.SetDefaultColor(Color.white);
# x.setlineweight(1);
smallup.hidebubble();
plot smalldwn = if (show_engulfing_arrows1 and engulf[1] and bardir[1] == -1) then high*1.006 else na;
smalldwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
smalldwn.SetDefaultColor(Color.white);
# x.setlineweight(1);
smalldwn.hidebubble();
#------------------------------
#
# hide the default candles
# HidePricePlot();
# input hide_candles = yes;
# HidePricePlot(hide_candles);
#