 # 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. ### 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 + (openMA + highMA + lowMA + closeMA) /4.0)/2.0), open);
haClose = ((OpenMA + HighMA + LowMA + CloseMA)/4.0) ;

case Vervoort:
haOpen = CompoundValue(1, ( (haOpen + (openMA + highMA + lowMA + closeMA) /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;

def higherhigh = hih-o>hih-o;
def lowerlow = o-halow<o-halow;
def highesthigh = hih>hih;
def lowestlow = halow<halow;

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 then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff 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 then Diff2.color("Positive and Up") else Diff2.color("Positive and Down") else if Diff2 < Diff2 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;``````

### HAMA Upper Study 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 + (openMA + highMA + lowMA + closeMA) /4.0)/2.0), open);
haClose = ((OpenMA + HighMA + LowMA + CloseMA)/4.0) ;

case Vervoort:
haOpen = CompoundValue(1, ( (haOpen + (openMA + highMA + lowMA + closeMA) /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;

def higherhigh = hih-o>hih-o;
def lowerlow = o-halow<o-halow;
def highesthigh = hih>hih;
def lowestlow = halow<halow;

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 then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff 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 then Diff2.color("Positive and Up") else Diff2.color("Positive and Down") else if Diff2 < Diff2 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);``````

### Hull HAMA Lower 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 + (openMA + highMA + lowMA + closeMA) /4.0)/2.0), open);
haClose = ((OpenMA + HighMA + LowMA + CloseMA)/4.0) ;

case Vervoort:
haOpen = CompoundValue(1, ( (haOpen + (openMA + highMA + lowMA + closeMA) /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;

def higherhigh = hih-o>hih-o;
def lowerlow = o-halow<o-halow;
def highesthigh = hih>hih;
def lowestlow = halow<halow;

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 then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff 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 then Diff2.color("Positive and Up") else Diff2.color("Positive and Down") else if Diff2 < Diff2 then Diff2.color("Negative and Down") else Diff2.color("Negative and Up"));

def hph = diff>diff;
def hpl = diff<diff;
def lph = diff2>diff2;
def lpl = diff2<diff2;

#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;``````

Honorable mentions: I prefer the hull HAMA and it fits nicely with either the TMO or the DPO MOBO.

Last edited by a moderator:
• • s1111, ALV, MerryDay and 2 others

#### BillW

##### New member
OMG! Yes I'm a huge fan of @rad14733 DPO MOBO and this HULL HAMA will be the second lower indicator I've been searching for!

• MerryDay and WbKiki