#elephant2_stops
# https://usethinkscript.com/threads/looking-to-move-stop-up-large-candles.16878/
# on large candles, go long or short
# An elephant candle is bigger than at least the previous 5 candles.
# preverable the body is 2x as large.
# The candle also is a full body candle generally with little to no wick.
def na = Double.NaN;
def bn = barnumber();
def up = close > open;
def dwn = close < open;
def ht = high - low;
def body = BodyHeight();
def wicks = ht - body;
input elephant_bars = 5;
input elephant_size_ratio = 2.0;
input wicks_to_body_percent = 20.0;
def hihi = Highest(ht[1], elephant_bars);
def el_size = body >= (elephant_size_ratio * hihi);
def el_wicks = (100 * wicks / ht) <= wicks_to_body_percent;
def el = el_size and el_wicks;
def elup = el and up;
def eldwn = el and dwn;
def dir = if bn == 1 then 0
# else if el[-1] then 0
else if elup then 1
else if eldwn then -1
else dir[1];
def stop = if bn == 1 then na
else if el[-1] then na
else if elup then low
else if eldwn then high
else stop[1];
plot z1 = stop;
#z1.setdefaultcolor(color.gray);
z1.AssignValueColor(if dir > 0 then color.green else if dir < 0 then color.red else color.gray);
input show_elephant_arrows = yes;
def y = 0.002;
plot zelup = if show_elephant_arrows and elup then low*(1-y) else na;
#zelup.SetPaintingStrategy(PaintingStrategy.POINTS);
zelup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#zelup.SetDefaultColor(Color.green);
zelup.SetDefaultColor(Color.cyan);
zelup.setlineweight(4);
zelup.hidebubble();
plot zeldwn = if show_elephant_arrows and eldwn then high*(1+y) else na;
#zeldwn.SetPaintingStrategy(PaintingStrategy.POINTS);
zeldwn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#zeldwn.SetDefaultColor(Color.red);
zeldwn.SetDefaultColor(Color.cyan);
zeldwn.setlineweight(4);
zeldwn.hidebubble();
input show_sell_squares = yes;
plot upstopsell = if show_sell_squares and dir > 0 and close crosses below stop then stop else na;
# upstopsell.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_DOWN);
upstopsell.SetPaintingStrategy(PaintingStrategy.squares);
upstopsell.SetDefaultColor(Color.yellow);
upstopsell.setlineweight(5);
plot dwnstopsell = if show_sell_squares and dir < 0 and close crosses above stop then stop else na;
# dwnstopsell.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_up);
dwnstopsell.SetPaintingStrategy(PaintingStrategy.squares);
dwnstopsell.SetDefaultColor(Color.yellow);
dwnstopsell.setlineweight(5);
input alerts = yes;
alert((alerts and dir < 0 and close crosses above stop), "crossed up" ,alert.BAR, sound.DING);
alert((alerts and dir > 0 and close crosses below stop), "crossed down" ,alert.BAR, sound.bell);
#-------------------------------
#AddVerticalLine(el, "-");
AddChartBubble(0, low * 0.994,
body + " b\n" +
hihi + " hi\n" +
el_size + "\n\n" +
ht + " ht\n" +
wicks + " w\n" +
(100 * wicks / ht) + " w%\n" +
el_wicks + "\n\n" +
el
, (if el then Color.YELLOW else Color.GRAY), no);
#