Hull HAMA Wave Indicator for ThinkorSwim

WbKiki

New member
VIP
A user on the Discord server, Brandon_L, sent in this cool indicator. As he explains, the HAMA indicator was popularized by Brian Watt and Cid Da Silva, it changes in height to measure severity of trends.

He messaged me with a question about some kind of indicator which changed color when the length of the wicks/candle of the HAMA changed.

Here are the couple iterations that I came up with.

Screenshot-9.png


HAMA Lower Study

Code:
declare lower;

input period = 21;
input hideCandles = NO;
input candleSmoothing = {default Valcu, Vervoort};

DefineGlobalColor("RisingMA", color.uptick);
DefineGlobalColor("FallingMA", color.downtick);

input movingAverageType = {default TEMA, Exponential, Weighted, Hull, Variable, SIMPLE};

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Simple:
    openMA = compoundValue(1, Average(open, period), open);
    closeMA = compoundValue(1, Average(close, period), close);
    highMA = compoundValue(1, Average(high, period), high);
    lowMA = compoundValue(1, Average(low, period), low);
case Exponential:
    openMA = compoundValue(1, ExpAverage(open, period), open);
    closeMA = compoundValue(1, ExpAverage(close, period), close);
    highMA = compoundValue(1, ExpAverage(high, period), high);
    lowMA = compoundValue(1, ExpAverage(low, period), low);
case Weighted:
    openMA = compoundValue(1, WMA(open, period), open);
    closeMA = compoundValue(1, WMA(close, period), close);
    highMA = compoundValue(1, WMA(high, period), high);
    lowMA = compoundValue(1, WMA(low, period), low);
Case Hull:
    openMA = compoundValue(1, HullMovingAvg(open, period), open);
    closeMA = compoundValue(1,  HullMovingAvg(close, period), close);
    highMA = compoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = compoundValue(1,  HullMovingAvg(low, period), low);
case variable:
    openMA = compoundValue(1, VariableMA(open, period), open);
    closeMA = compoundValue(1, VariableMA(close, period), close);
    highMA = compoundValue(1, VariableMA(high, period), high);
    lowMA = compoundValue(1, VariableMA(low, period), low);
case TEMA:
    openMA = compoundValue(1, TEMA(open, period), open);
    closeMA = compoundValue(1, TEMA(close, period), close);
    highMA = compoundValue(1, TEMA(high, period), high);
    lowMA = compoundValue(1, TEMA(low, period), low);
}

hidePricePlot(hideCandles);

def haOpen;
def haClose;

switch(candleSmoothing) {
case Valcu:

    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
    haClose = ((OpenMA + HighMA + LowMA + CloseMA)/4.0) ;
  
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
    haClose = ((((OpenMA + HighMA + LowMA + CloseMA)/4.0) + haOpen + Max(HighMA, haOpen) + Min(LowMA, haOpen))/4.0);

}

plot o = haopen;
o.hide();

def haLow =  min(lowMA, haOpen);
def haHigh = max(highMA,haOpen);

def haopen1 = if haopen>haclose
              then HAopen
              else double.nan;
def HAhigh1   = if haopen>=haclose
              then hahigh
              else double.nan;
def HAlow1    = if haopen>=haclose
              then halow
              else double.nan;

def hih = haHigh;
def lo = haLow;
#AddCloud(hih, o, Color.GREEN, Color.GREEN);
#AddCloud(lo, o, Color.RED, Color.RED);

def higherhigh = hih[0]-o[0]>hih[1]-o[1];
def lowerlow = o[1]-halow[1]<o[0]-halow[0];
def highesthigh = hih[0]>hih[1];
def lowestlow = halow[0]<halow[1];

def h = higherhigh;
def l = lowerlow;
def h1 = highesthigh;
def l1 = lowestlow;

#AddChart(high = haHigh, low  = haLow, open = o, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("RisingMA"), fallColor = GlobalColor("FallingMA"), neutralColor = color.gray);

#AddChart(high = haHigh1, low  = haLow1, open = haopen1, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("FallingMA"), fallColor = GlobalColor("RisingMA"), neutralColor = color.gray);

def dif = hih-o;
plot diff = dif;
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
#Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));

def dif2 = lo-o;
plot diff2 = dif2;
Diff2.SetDefaultColor(GetColor(5));
Diff2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff2.SetLineWeight(3);
#Diff2.AssignValueColor(if Diff2 >= 0 then if Diff2 > Diff2[1] then Diff2.color("Positive and Up") else Diff2.color("Positive and Down") else if Diff2 < Diff2[1] then Diff2.color("Negative and Down") else Diff2.color("Negative and Up"));


Diff.AssignValueColor(if l1 then Color.DARK_RED else if l then color.red else if h then color.green else if h1 then color.dark_green else Color.BLUE);
Diff2.AssignValueColor(if h then color.green else if l then color.red else if l1 then Color.DARK_RED else if h1 then color.dark_green else Color.BLUE);
plot z = 0;

Shareable link: https://tos.mx/vSupYCR

HAMA Upper Study

Screenshot-10.png


Code:
input period = 21;
input hideCandles = NO;
input candleSmoothing = {default Valcu, Vervoort};

DefineGlobalColor("RisingMA", color.uptick);
DefineGlobalColor("FallingMA", color.downtick);

input movingAverageType = {default TEMA, Exponential, Weighted, Hull, Variable, SIMPLE};

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Simple:
    openMA = compoundValue(1, Average(open, period), open);
    closeMA = compoundValue(1, Average(close, period), close);
    highMA = compoundValue(1, Average(high, period), high);
    lowMA = compoundValue(1, Average(low, period), low);
case Exponential:
    openMA = compoundValue(1, ExpAverage(open, period), open);
    closeMA = compoundValue(1, ExpAverage(close, period), close);
    highMA = compoundValue(1, ExpAverage(high, period), high);
    lowMA = compoundValue(1, ExpAverage(low, period), low);
case Weighted:
    openMA = compoundValue(1, WMA(open, period), open);
    closeMA = compoundValue(1, WMA(close, period), close);
    highMA = compoundValue(1, WMA(high, period), high);
    lowMA = compoundValue(1, WMA(low, period), low);
Case Hull:
    openMA = compoundValue(1, HullMovingAvg(open, period), open);
    closeMA = compoundValue(1,  HullMovingAvg(close, period), close);
    highMA = compoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = compoundValue(1,  HullMovingAvg(low, period), low);
case variable:
    openMA = compoundValue(1, VariableMA(open, period), open);
    closeMA = compoundValue(1, VariableMA(close, period), close);
    highMA = compoundValue(1, VariableMA(high, period), high);
    lowMA = compoundValue(1, VariableMA(low, period), low);
case TEMA:
    openMA = compoundValue(1, TEMA(open, period), open);
    closeMA = compoundValue(1, TEMA(close, period), close);
    highMA = compoundValue(1, TEMA(high, period), high);
    lowMA = compoundValue(1, TEMA(low, period), low);
}

hidePricePlot(hideCandles);

def haOpen;
def haClose;
plot hacloseU = haclose;
plot haopenU = haopen;

switch(candleSmoothing) {
case Valcu:

    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
    haClose = ((OpenMA + HighMA + LowMA + CloseMA)/4.0) ;
  
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
    haClose = ((((OpenMA + HighMA + LowMA + CloseMA)/4.0) + haOpen + Max(HighMA, haOpen) + Min(LowMA, haOpen))/4.0);

}

plot o = haopen;
o.hide();

def haLow =  min(lowMA, haOpen);
def haHigh = max(highMA,haOpen);

def haopen1 = if haopen>haclose
              then HAopen
              else double.nan;
def HAhigh1   = if haopen>=haclose
              then hahigh
              else double.nan;
def HAlow1    = if haopen>=haclose
              then halow
              else double.nan;

def hih = haHigh;
def lo = haLow;
AddCloud(hacloseU, o, Color.light_green, Color.light_red);
#AddCloud(lo, o, Color.RED, Color.RED);

def higherhigh = hih[0]-o[0]>hih[1]-o[1];
def lowerlow = o[1]-halow[1]<o[0]-halow[0];
def highesthigh = hih[0]>hih[1];
def lowestlow = halow[0]<halow[1];

def h = higherhigh;
def l = lowerlow;
def h1 = highesthigh;
def l1 = lowestlow;

#AddChart(high = haHigh, low  = haLow, open = o, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("RisingMA"), fallColor = GlobalColor("FallingMA"), neutralColor = color.gray);

#AddChart(high = haHigh1, low  = haLow1, open = haopen1, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("FallingMA"), fallColor = GlobalColor("RisingMA"), neutralColor = color.gray);

#def dif = hih-o;
#plot diff = dif;
#Diff.SetDefaultColor(GetColor(5));
#Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Diff.SetLineWeight(3);
#Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));

#def dif2 = lo-o;
#plot diff2 = dif2;
#Diff2.SetDefaultColor(GetColor(5));
#Diff2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Diff2.SetLineWeight(3);
#Diff2.AssignValueColor(if Diff2 >= 0 then if Diff2 > Diff2[1] then Diff2.color("Positive and Up") else Diff2.color("Positive and Down") else if Diff2 < Diff2[1] then Diff2.color("Negative and Down") else Diff2.color("Negative and Up"));


hacloseU.AssignValueColor(if l1 then Color.DARK_RED else if l then color.red else if h then color.green else if h1 then color.dark_green else Color.BLUE);
hacloseU.SetLineWeight(3);
haopenU.AssignValueColor(if h then color.green else if l then color.red else if l1 then Color.DARK_RED else if h1 then color.dark_green else Color.BLUE);
haopenU.SetLineWeight(3);

Shareable Link: https://tos.mx/jQYaomg

Hull HAMA Lower

Screenshot-11.png


Code:
declare lower;

input period = 21;
input hideCandles = NO;
input candleSmoothing = {default Valcu, Vervoort};

DefineGlobalColor("RisingMA", color.uptick);
DefineGlobalColor("FallingMA", color.downtick);

input movingAverageType = {TEMA, Exponential, Weighted, Default Hull, Variable, SIMPLE};

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Simple:
    openMA = compoundValue(1, Average(open, period), open);
    closeMA = compoundValue(1, Average(close, period), close);
    highMA = compoundValue(1, Average(high, period), high);
    lowMA = compoundValue(1, Average(low, period), low);
case Exponential:
    openMA = compoundValue(1, ExpAverage(open, period), open);
    closeMA = compoundValue(1, ExpAverage(close, period), close);
    highMA = compoundValue(1, ExpAverage(high, period), high);
    lowMA = compoundValue(1, ExpAverage(low, period), low);
case Weighted:
    openMA = compoundValue(1, WMA(open, period), open);
    closeMA = compoundValue(1, WMA(close, period), close);
    highMA = compoundValue(1, WMA(high, period), high);
    lowMA = compoundValue(1, WMA(low, period), low);
Case Hull:
    openMA = compoundValue(1, HullMovingAvg(open, period), open);
    closeMA = compoundValue(1,  HullMovingAvg(close, period), close);
    highMA = compoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = compoundValue(1,  HullMovingAvg(low, period), low);
case variable:
    openMA = compoundValue(1, VariableMA(open, period), open);
    closeMA = compoundValue(1, VariableMA(close, period), close);
    highMA = compoundValue(1, VariableMA(high, period), high);
    lowMA = compoundValue(1, VariableMA(low, period), low);
case TEMA:
    openMA = compoundValue(1, TEMA(open, period), open);
    closeMA = compoundValue(1, TEMA(close, period), close);
    highMA = compoundValue(1, TEMA(high, period), high);
    lowMA = compoundValue(1, TEMA(low, period), low);
}

hidePricePlot(hideCandles);

def haOpen;
def haClose;

switch(candleSmoothing) {
case Valcu:

    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
    haClose = ((OpenMA + HighMA + LowMA + CloseMA)/4.0) ;
  
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) /4.0)/2.0), open);
    haClose = ((((OpenMA + HighMA + LowMA + CloseMA)/4.0) + haOpen + Max(HighMA, haOpen) + Min(LowMA, haOpen))/4.0);

}

plot o = haopen;
o.hide();

def haLow =  min(lowMA, haOpen);
def haHigh = max(highMA,haOpen);

def haopen1 = if haopen>haclose
              then HAopen
              else double.nan;
def HAhigh1   = if haopen>=haclose
              then hahigh
              else double.nan;
def HAlow1    = if haopen>=haclose
              then halow
              else double.nan;

def hih = haHigh;
def lo = haLow;
#AddCloud(hih, o, Color.GREEN, Color.GREEN);
#AddCloud(lo, o, Color.RED, Color.RED);

def higherhigh = hih[0]-o[0]>hih[1]-o[1];
def lowerlow = o[1]-halow[1]<o[0]-halow[0];
def highesthigh = hih[0]>hih[1];
def lowestlow = halow[0]<halow[1];

def h = higherhigh;
def l = lowerlow;
def h1 = highesthigh;
def l1 = lowestlow;

#AddChart(high = haHigh, low  = haLow, open = o, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("RisingMA"), fallColor = GlobalColor("FallingMA"), neutralColor = color.gray);

#AddChart(high = haHigh1, low  = haLow1, open = haopen1, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("FallingMA"), fallColor = GlobalColor("RisingMA"), neutralColor = color.gray);

def dif = hih-o;
plot diff = dif;
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
#Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));

def dif2 = lo-o;
plot diff2 = dif2;
Diff2.SetDefaultColor(GetColor(5));
Diff2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff2.SetLineWeight(3);
#Diff2.AssignValueColor(if Diff2 >= 0 then if Diff2 > Diff2[1] then Diff2.color("Positive and Up") else Diff2.color("Positive and Down") else if Diff2 < Diff2[1] then Diff2.color("Negative and Down") else Diff2.color("Negative and Up"));

def hph = diff[0]>diff[1];
def hpl = diff[0]<diff[1];
def lph = diff2[0]>diff2[1];
def lpl = diff2[0]<diff2[1];

#Diff.AssignValueColor(if l1 then Color.DARK_RED else if l then color.red else if h then color.green else if h1 then color.dark_green else Color.BLUE);
#Diff2.AssignValueColor(if h then color.green else if l then color.red else if l1 then Color.DARK_RED else if h1 then color.dark_green else Color.BLUE);
Diff.AssignValueColor(if hph then color.green else if hpl then color.dark_green else Color.BLUE);
Diff2.AssignValueColor(if lph then color.dark_red else if lpl then color.red else Color.BLUE);

plot z = 0;

Shareable link: https://tos.mx/afi075z

Honorable mentions: I prefer the hull HAMA and it fits nicely with either the TMO or the DPO MOBO.
 
Last edited by a moderator:

Similar threads

Top