HMA Watchlist with counter for TOS

Platform
  1. Thinkorswim
Code:
#Watchlist studies lag behind charts, so no study is perfect nor is the counts exact.
#Note: Script should match the study and extended hour's time frame used
#http://tos.mx/oFWuMjy Hull Watchlist with counter
#http://tos.mx/Ju7R6go Hull Ribbon Mod Used
#FYI: The point of this watchlist is to see when the Hull Ribbon is changing direction, The count will change when the ribbon color changes or gap brake.  It does not mean the trend has change direction or has changed color, candles are only used for the counting. any "Loading" conflicts could be related to TOS, user Limits, ect.
#Modification By Gatekeeper 12272021...

#HMA Watchlist with Count
input length = 55; #Length (180-200 for floating S/R , 55 for swing entry)

def hma;
hma = wma(2 * wma(close, length / 2) - wma(close, length), round(sqrt(length)));

def hull = hma;
def Mhull = hull[0];
def transition = hull > hull[1];

#AddLabel(yes, If transition then "U" else "D",  If transition then color.GREEN else COLOR.RED);

######XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
def UpTrend = if hull > hull[1]  then 1 else 0;
def DownTrend = if hull < hull[1]  then 1 else 0;

def bnumUp;
def bnumDown;
def closeUpTrendStart;
def closeDownTrendStart;
def UpTrendBarCount;
def DownTrendBarCount;
if UpTrend and (!UpTrend[1] or DownTrend[1]) {
    bnumUp = BarNumber();
    bnumDown = 0;
    closeUpTrendStart = close;
    closeDownTrendStart = 0;
    UpTrendBarCount = 1;
    DownTrendBarCount = 0;
} else if UpTrend {
    bnumUp = bnumUp[1];
    bnumDown = 0;
    closeUpTrendStart = closeUpTrendStart[1];
    closeDownTrendStart = 0;
    UpTrendBarCount = UpTrendBarCount[1] + 1;
    DownTrendBarCount = 0;
} else if DownTrend and (!DownTrend[1] or UpTrend[1]) {
    bnumUp = 0;
    bnumDown = BarNumber();
    closeDownTrendStart = close;
    closeUpTrendStart = 0;
    UpTrendBarCount = 0;
    DownTrendBarCount = 1;
} else if DownTrend {
    bnumDown = bnumDown[1];
    closeDownTrendStart = closeDownTrendStart[1];
    DownTrendBarCount = DownTrendBarCount[1] + 1;
    bnumUp = 0;
    closeUpTrendStart = 0;
    UpTrendBarCount = 0;
} else {
    bnumUp = 0;
    bnumDown = 0;
    closeUpTrendStart = 0;
    closeDownTrendStart = 0;
    UpTrendBarCount = 0;
    DownTrendBarCount = 0;
}


def GetTrend = if Uptrend then 1 else if  DownTrend then -1 else 0;

AddLabel (yes, if GetTrend == 1 then "U" + UpTrendBarCount  else if   GetTrend == -1  then "D" + DownTrendBarCount else "", if  GetTrend == 1 then Color.GREEN else if  GetTrend == -1 then Color.RED else Color.WHITE);
 
Last edited:
Top