# Trading Warz Candles
# Assembled for https://b4indicators.com/threads/trading-warz-candles.117/
# v1.0 - barbaros
# v1.1 - barbaros - added colors and options
input ShowNirvana = yes;
input ShowHollyGrail = yes;
DefineGlobalColor("InsidePower", Color.YELLOW);
DefineGlobalColor("OutsidePower", Color.WHITE);
DefineGlobalColor("Nirvana", Color.BLUE);
DefineGlobalColor("HollyGrail", Color.YELLOW);
def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
def InsidePower =
((Sum(IsUp, 1)[1] >= 0)) and
((Sum(IsUp, 1)[0] >= 0)) and
Lowest(low[1], 1) <= Lowest(low[0], 1) and
Highest(high[1], 1) >= Highest(high[0], 1);
def OutsidePower =
((Sum(IsUp, 1)[1] >= 0)) and
((Sum(IsUp, 1)[0] >= 0)) and
Lowest(low[1], 1) > Lowest(low[0], 1) and
Highest(high[1], 1) < Highest(high[0], 1);
def HollyGrail =
((Sum(IsUp, 1)[2] >= 0)) and
((Sum(IsUp, 1)[1] >= 0)) and
((Sum(IsUp, 1)[0] >= 0)) and
Lowest(low[2], 1) > Lowest(low[1], 1) and
Lowest(low[1], 1) < Lowest(low[0], 1) and
Highest(high[2], 1) < Highest(high[1], 1) and
Highest(high[1], 1) > Highest(high[0], 1);
def Nirvana =
((Sum(IsUp, 1)[2] >= 0)) and
((Sum(IsUp, 1)[1] >= 0)) and
((Sum(IsUp, 1)[0] >= 0)) and
Highest(high[1], 1) > Highest(high[0], 1) and
Lowest(low[2], 1) < Lowest(low[1], 1) and
Highest(high[2], 1) > Highest(high[1], 1) and
Lowest(low[1], 1) < Lowest(low[0], 1);
AssignPriceColor(
if InsidePower then GlobalColor("InsidePower")
else if OutsidePower then GlobalColor("OutsidePower")
else Color.CURRENT
);
AddCloud(
if ShowHollyGrail and (HollyGrail or HollyGrail[-1]) then Double.POSITIVE_INFINITY else Double.NaN,
if ShowHollyGrail and (HollyGrail or HollyGrail[-1]) then Double.NEGATIVE_INFINITY else Double.NaN,
GlobalColor("HollyGrail"), GlobalColor("HollyGrail")
);
AddCloud(
if ShowNirvana and (Nirvana or Nirvana[-1]) then Double.POSITIVE_INFINITY else Double.NaN,
if ShowNirvana and (Nirvana or Nirvana[-1]) then Double.NEGATIVE_INFINITY else Double.NaN,
GlobalColor("Nirvana"), GlobalColor("Nirvana")
);