#pin_bar_tail_bar
#https://usethinkscript.com/threads/is-it-possible-to-create-a-script-based-on-double-topping-tails.17229/
#Is it possible to create a script based on double topping tails
def t = ticksize();
#addlabel(1, t);
def zero = (t/2);
def ht = high - low;
def body = if BodyHeight() == 0 then zero else bodyheight();
def bodytop = Max(open, close);
def bodybot = Min(open, close);
def wicktop = if (high - bodytop) == 0 then zero else (high - bodytop);
def wickbot = if (bodybot - low) == 0 then zero else (bodybot - low);
def up = close > open;
def dwn = close < open;
input use_bar_direction = no;
# pin bar - small body
# tail bar - bigger body
def body_ht = body/ht;
# ratios , top wick to bottom wick
def wickt_wickb = wicktop/wickbot;
def wickb_wickt = wickbot/wicktop;
def wick_long_wick_short = max(wicktop, wickbot) / min(wicktop, wickbot);
# use these
# ratios , wick to body
def wickt_body = wicktop/body;
def wickb_body = wickbot/body;
# ratios
#input pin_shortwick_lower_rng = 0.3;
input pin_shortwick_lower_rng = 0.0;
input pin_shortwick_upper_rng = 1.0;
input pin_longwick_min = 1.9;
def tail_shortwick_max = pin_shortwick_lower_rng;
def tail_longwick_upper_rng = pin_longwick_min;
def tail_longwick_lower_rng = pin_shortwick_upper_rng;
def pin_bull = (wickt_body >= pin_shortwick_lower_rng) and (wickt_body <= pin_shortwick_upper_rng) and (wickb_body > pin_longwick_min);
def pin_bear = (wickt_body > pin_longwick_min) and (wickb_body >= pin_shortwick_lower_rng) and (wickb_body <= pin_shortwick_upper_rng);
def tail_bull = (wickt_body <= tail_shortwick_max) and (wickb_body >= tail_longwick_lower_rng) and (wickb_body <= tail_longwick_upper_rng);
def tail_bear = (wickt_body >= tail_longwick_lower_rng) and (wickt_body <= tail_longwick_upper_rng) and (wickb_body <= tail_shortwick_max);
addchartbubble(pin_bull, low, "P", color.green, no);
addchartbubble(pin_bear, high, "P", color.red, yes);
addchartbubble(tail_bull, low, "T", color.green, no);
addchartbubble(tail_bear, high, "T", color.red, yes);
# if 2 in a row, then vert line
def bull_dbl = ((pin_bull[1] and pin_bull[0]) or (pin_bull[1] and tail_bull[0]) or (tail_bull[1] and tail_bull[0]) or (tail_bull[1] and pin_bull[0]));
def bear_dbl = ((pin_bear[1] and pin_bear[0]) or (pin_bear[1] and tail_bear[0]) or (tail_bear[1] and tail_bear[0]) or (tail_bear[1] and pin_bear[0]));
addverticalline(bull_dbl, "Double Bull", color.cyan);
addverticalline(bear_dbl, "Double Bear", color.yellow);
input test1 = no;
input test2_all = no;
addchartbubble((test1 and (pin_bull or tail_bull)), low,
wickt_body + "\n" +
wickb_body
, color.cyan, no);
addchartbubble((test2_all or (test1 and (pin_bear or tail_bear))), high,
wickt_body + "\n" +
wickb_body + "\n" +
wick_long_wick_short + " wL/wS"
, color.yellow, yes);
#