• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Hull Moving Average Pack for ThinkorSwim

ykd2018x

Member
2019 Donor
VIP
This script from TradingView provides a few variations of the Hull Moving Average indicator. Please convert them to ThinkorSwim.

https://www.tradingview.com/script/hg92pFwS-Hull-Suite/

Code:
//@version=4
//Basic Hull Ma Pack tinkered by InSilico
study("Hull Suite by InSilico", overlay=true)

//INPUT
src = input(close, title="Source")
modeSwitch = input("Hma", title="Hull Variation", options=["Hma", "Thma", "Ehma"])
length = input(55, title="Length(180-200 for floating S/R , 55 for swing entry)")
lengthMult = input(1.0, title="Length multiplier (Used to view higher timeframes with straight band)")

useHtf = input(false, title="Show Hull MA from X timeframe? (good for scalping)")
htf = input("240", title="Higher timeframe", type=input.resolution)

switchColor = input(true, "Color Hull according to trend?")
candleCol = input(false,title="Color candles based on Hull's Trend?")
visualSwitch  = input(true, title="Show as a Band?")
thicknesSwitch = input(1, title="Line Thickness")
transpSwitch = input(40, title="Band Transparency",step=5)

//FUNCTIONS
//HMA
HMA(_src, _length) =>  wma(2 * wma(_src, _length / 2) - wma(_src, _length), round(sqrt(_length)))
//EHMA   
EHMA(_src, _length) =>  ema(2 * ema(_src, _length / 2) - ema(_src, _length), round(sqrt(_length)))
//THMA   
THMA(_src, _length) =>  wma(wma(_src,_length / 3) * 3 - wma(_src, _length / 2) - wma(_src, _length), _length)
    
//SWITCH
Mode(modeSwitch, src, len) =>
      modeSwitch == "Hma"  ? HMA(src, len) :
      modeSwitch == "Ehma" ? EHMA(src, len) :
      modeSwitch == "Thma" ? THMA(src, len/2) : na

//OUT
_hull = Mode(modeSwitch, src, int(length * lengthMult))
HULL = useHtf ? security(syminfo.ticker, htf, _hull) : _hull
MHULL = HULL[0]
SHULL = HULL[2]

//COLOR
hullColor = switchColor ? (HULL > HULL[2] ? #00ff00 : #ff0000) : #ff9800

//PLOT
///< Frame
Fi1 = plot(MHULL, title="MHULL", color=hullColor, linewidth=thicknesSwitch, transp=50)
Fi2 = plot(visualSwitch ? SHULL : na, title="SHULL", color=hullColor, linewidth=thicknesSwitch, transp=50)
///< Ending Filler
fill(Fi1, Fi2, title="Band Filler", color=hullColor, transp=transpSwitch)
///BARCOLOR
barcolor(color = candleCol ? (switchColor ? hullColor : na) : na)
 
Last edited by a moderator:
Solution
took a pass at porting it:

HMA
cAz6Qrf.png


EHMA
96bRpzV.png


THMA
yNCgIsD.png


Ruby:
#Basic Hull Ma Pack tinkered by InSilico
#Original Port from https://www.tradingview.com/script/hg92pFwS-Hull-Suite
#
#2019.10.30 1.0 @diazlaz - Original Port
#

#INPUTS

input modeSwitch = {default "Hma", "Thma", "Ehma"}; #Hull Variation
input length = 55; #Length(180-200 for floating S/R , 55 for swing entry)
input switchColor = yes; #Color Hull according to trend?
input candleCol = yes; #Color candles based on Hull's Trend?
input visualSwitch = yes; #Show as a Band?
input thicknesSwitch = 2; #Line Thickness
input showLabels = yes...

diazlaz

Well-known member
2019 Donor
VIP
took a pass at porting it:

HMA
cAz6Qrf.png


EHMA
96bRpzV.png


THMA
yNCgIsD.png


Ruby:
#Basic Hull Ma Pack tinkered by InSilico
#Original Port from https://www.tradingview.com/script/hg92pFwS-Hull-Suite
#
#2019.10.30 1.0 @diazlaz - Original Port
#

#INPUTS

input modeSwitch = {default "Hma", "Thma", "Ehma"}; #Hull Variation
input length = 55; #Length(180-200 for floating S/R , 55 for swing entry)
input switchColor = yes; #Color Hull according to trend?
input candleCol = yes; #Color candles based on Hull's Trend?
input visualSwitch = yes; #Show as a Band?
input thicknesSwitch = 2; #Line Thickness
input showLabels = yes;
input src = close; #Source

addLabel (showLabels, modeSwitch, COLOR.ORANGE);
def na = Double.NaN;

# HMA

def hma;
switch (modeSwitch) {
case "Hma":
    hma = wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)));
case "Ehma":
    hma = expAverage(2 * expAverage(src, length / 2) - expAverage(src, length), round(sqrt(length)));
case "Thma":
    hma = wma(wma(src,(length/2) / 3) * 3 - wma(src, (length/2) / 2) - wma(src, (length/2)), (length/2));
}

# PLOTS

def HULL = hma;
def MHULL = HULL[0];
def SHULL = HULL[2];

plot Fi1 = MHULL;
Fi1.AssignValueColor(
if HULL > HULL[2] then COLOR.GREEN else COLOR.RED
);
Fi1.SetLineWeight(thicknesSwitch);

plot Fi2 = SHULL;
Fi2.AssignValueColor(
if HULL > HULL[2] then COLOR.GREEN else COLOR.RED
);
Fi2.SetLineWeight(thicknesSwitch);
Fi2.SetHiding(!visualSwitch);

AddCloud (if visualSwitch then Fi1 else na, Fi2);

# COLORBARS
AssignPriceColor(
if !candleCol then
Color.CURRENT
else
if HULL > HULL[2] then COLOR.GREEN else COLOR.RED
);

#END OF HULL

Please provide any feedback, bugs, backtests, experiences, optimizations on how to best use it.
 
Solution

SmellyCat

New member
I've looked at it with Crude on a daily chart with the 55 setting. It confirms a trend VERY well, however, it is a bit too slow for crude for an entry, but that is only crude. And when I change it to, say a 34 period, it generated a few too many whip saws on crude. But Heck! to confirm a trend like it does is awesome! it would keep someone in a swing trade much longer and it appears to capture much more of a longer swing trade if one could follow the past signals.
 

tomsk

Well-known member
VIP
@shizah I have modified @diazlaz Hull Pack study to add alerts. It now rings an alert whenever the color transitions from green to red or vice versa. Here is the revised study, I have tested it both ways on the /ES. Have fun
Code:
#Basic Hull Ma Pack tinkered by InSilico
#Original Port from https://www.tradingview.com/script/hg92pFwS-Hull-Suite
#
# 2019.10.30 1.0 [USER=258]@diazlaz[/USER] - Original Port
# 2019.11.14 2.0 [USER=1369]@tomsk[/USER]   - Added alerts for color bar transitions

input modeSwitch = {default "Hma", "Thma", "Ehma"}; #Hull Variation
input length = 55; #Length(180-200 for floating S/R , 55 for swing entry)
input switchColor = yes; #Color Hull according to trend?
input candleCol = yes; #Color candles based on Hull's Trend?
input visualSwitch = yes; #Show as a Band?
input thicknesSwitch = 2; #Line Thickness
input showLabels = yes;
input src = close; #Source

addLabel (showLabels, modeSwitch, Color.ORANGE);

def hma;
switch (modeSwitch) {
case "Hma":
    hma = wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)));
case "Ehma":
    hma = expAverage(2 * expAverage(src, length / 2) - expAverage(src, length), round(sqrt(length)));
case "Thma":
    hma = wma(wma(src,(length/2) / 3) * 3 - wma(src, (length/2) / 2) - wma(src, (length/2)), (length/2));
}

def hull = hma;
def Mhull = hull[0];
def Shull = hull[2];
def transition = hull > hull[2];

plot Fi1 = Mhull;
Fi1.AssignValueColor(if transition then Color.GREEN else Color.RED);
Fi1.SetLineWeight(thicknesSwitch);

plot Fi2 = Shull;
Fi2.AssignValueColor(if transition then Color.GREEN else Color.RED);
Fi2.SetLineWeight(thicknesSwitch);
Fi2.SetHiding(!visualSwitch);

AddCloud (if visualSwitch then Fi1 else Double.NaN, Fi2);
AssignPriceColor(if !candleCol then Color.CURRENT else if transition then COLOR.GREEN else COLOR.RED);

Alert((!transition[1] and transition) or (transition[1] and !transition), "Hull Color Change", Alert.BAR, Sound.RING);
# END
 

tomsk

Well-known member
VIP
@tomsk How do you post this study as a scan?


@mailbagman2000 Here is the study converted into a scan. Note that there are two plot statements in the scan. I have configured this for the bullish case. If you'd like to use the bullish bearish scan, just comment out the bullish scan and uncomment the bearish scan. All this is listed at the end of the file. In case you're not sure, please read the following post.

https://usethinkscript.com/threads/how-to-use-the-tos-scanner.284/#post-10505
Here then is your COMPLETED scan code. I have tested this against a scan of the S&P 500 using daily aggregation a few minutes ago. A bullish scan has 4 results while a bearish scan has 5 results.

Code:
# Basic Hull Ma Pack Scan
# tomsk
# 12.27.2019

# Basic Hull Ma Pack tinkered by InSilico
# Original Port from https://www.tradingview.com/script/hg92pFwS-Hull-Suite

input modeSwitch = {default "Hma", "Thma", "Ehma"}; #Hull Variation
input length = 55; #Length(180-200 for floating S/R , 55 for swing entry)
input src = close; #Source

def hma;
switch (modeSwitch) {
case "Hma":
    hma = wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)));
case "Ehma":
    hma = expAverage(2 * expAverage(src, length / 2) - expAverage(src, length), round(sqrt(length)));
case "Thma":
    hma = wma(wma(src,(length/2) / 3) * 3 - wma(src, (length/2) / 2) - wma(src, (length/2)), (length/2));
}

def hull = hma;
def transition = hull > hull[2];

# Delete (#) the plot not needed

plot scanBull = !transition[1] and transition;
#plot scanBear = transition[1] and !transition;

# End Basic Hull Ma Pack Scan
 

mailbagman2000

Member
VIP
@mailbagman2000 Here is the study converted into a scan. Note that there are two plot statements in the scan. I have configured this for the bullish case. If you'd like to use the bullish bearish scan, just comment out the bullish scan and uncomment the bearish scan. All this is listed at the end of the file. In case you're not sure, please read the following post.

https://usethinkscript.com/threads/how-to-use-the-tos-scanner.284/#post-10505
Here then is your COMPLETED scan code. I have tested this against a scan of the S&P 500 using daily aggregation a few minutes ago. A bullish scan has 4 results while a bearish scan has 5 results.

Code:
# Basic Hull Ma Pack Scan
# tomsk
# 12.27.2019

# Basic Hull Ma Pack tinkered by InSilico
# Original Port from https://www.tradingview.com/script/hg92pFwS-Hull-Suite

input modeSwitch = {default "Hma", "Thma", "Ehma"}; #Hull Variation
input length = 55; #Length(180-200 for floating S/R , 55 for swing entry)
input src = close; #Source

def hma;
switch (modeSwitch) {
case "Hma":
    hma = wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)));
case "Ehma":
    hma = expAverage(2 * expAverage(src, length / 2) - expAverage(src, length), round(sqrt(length)));
case "Thma":
    hma = wma(wma(src,(length/2) / 3) * 3 - wma(src, (length/2) / 2) - wma(src, (length/2)), (length/2));
}

def hull = hma;
def transition = hull > hull[2];

# Delete (#) the plot not needed

plot scanBull = !transition[1] and transition;
#plot scanBear = transition[1] and !transition;

# End Basic Hull Ma Pack Scan
thanks will try and see how it works out.
 

C-Note Johnson

New member
I found this indicator for TradingView. Looks like it has potential. I tried to copy and paste it into ToS script editor. It puked. I was wondering if there was a way to convert it to ToS script. The pine code is below. Thanks, C-Note Johnson
Code:
//@version=4
study(title = "Hull VWMA", shorttitle="HVWMA", overlay = true)
len = input(8, minval=1)
src = input(close, title="Source")
lsrc = log(src)
geometric = input(type=input.bool,defval=false)
linewidth = input(3,minval=1)

corrvol = nz(volume) + 1  // Makes it properly handle charts where volume is only available for part of its history.
volume_wma(series,length) => wma(series*corrvol,length)/wma(corrvol,length)
volume_hma(series,length) => wma(2*volume_wma(series, length/2)-volume_wma(series, length), round(sqrt(length)))
oscillator_coloring(series) => series > 0 ? color.green : color.red

volume_hullma =  volume_hma(geometric ? lsrc : src,len)
out = geometric ? exp(volume_hullma) : volume_hullma
plot(out,color=oscillator_coloring(change(out)),linewidth=linewidth,title="Vol. Weighted Hull MA")
 

J007RMC

Well-known member
2019 Donor
Came across this Hull streategy and its working very well... https://tos.mx/XJnywQ4

lGxq2VA.png


Code:
#  One Note Download
addOrder(OrderType.BUY_AUTO, no);input price = close;
input length = 49;
input displace = 0;

plot HMA = MovingAverage(AverageType.HULL, price, length)[-displace];

HMA.DefineColor("Bullish", GetColor(1));
HMA.DefineColor("Bearish", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Bullish") else HMA.color("Bearish"));
AssignPriceColor(if HMA > HMA[1] then HMA.color("Bullish") else HMA.color("Bearish"));
addOrder(OrderType.BUY_AUTO, HMA crosses above HMA[1]);
addOrder(OrderType.Sell_AUTO, HMA crosses below HMA[1]);
 

Similar threads

Top