# HA Watchlist
# Paris
# 2.9.2019
# Paris: Vide Mobius comments that Mary's HA defs were wrong,
# changed the definitions for HAhigh, HAlow, and HAclose.
# Also added extra logic that resets counts for state transitions
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, HAopen[1] + HAclose[1], open[1] + close[1])/2;
HAhigh = Max(high, Max(HAclose, HAopen));
HAlow = Min(low, Min(HAclose, HAopen));
haclose = OHLC4;
def noWickBullish = haClose > haOpen and haOpen == haLow;
def nowickBearish = haClose < haOpen and haOpen == haHigh;
def bullStateCounter;
def bearStateCounter;
if noWickBullish
{
bullStateCounter = bullStateCounter[1] + 1;
bearStateCounter = 0;
}
else if nowickBearish
{
bullStateCounter = 0;
bearStateCounter = bearStateCounter[1] + 1;
}
else
{
bullStateCounter = bullStateCounter[1];
bearStateCounter = bearStateCounter[1];
}
addLabel(1, if bullStateCounter then "Buy Signal = " + bullStateCounter else “Sell Signal = " + bearStateCounter,
if bullStateCounter then color.green else color.red);
# Added logic that resets counts for state transitions
def BullCount = if bullStateCounter and bearStateCounter[1]
then 1
else if bullStateCounter >= 1
then BullCount[1] + 1
else BullCount[1];
def BearCount = if bearStateCounter and bullStateCounter[1]
then 1
else if bearStateCounter >= 1
then BearCount[1] + 1
else BearCount[1];
AddLabel(bullStateCounter, "Bull Count = " + BullCount, color.cyan);
AddLabel(bearStateCounter, "Bear Count = " + BearCount, color.pink);
AssignPriceColor(if HAclose > HAopen then color.green else color.red);
# End Code