Create MTF Hull

JP782

Active member
This is the orig main script for the Hull Suite Ive been trying every combination(2 examples below) to make into a MTF nothing works.

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

Can someone help me out??
---------------------------------------

Example:
def hma = wma(2 * (wma(src, length / 2) (period = time))- (wma(src, length), round(sqrt(length))(period = time)));

Eaxmple:
def hma = wma(period = time)(2 * wma(period = time)(src(period = time), length / 2) - wma(period = time)(src(period = time), length), round(period = time)(sqrt(period = time)(length)));
 
Solution
This is the orig main script for the Hull Suite Ive been trying every combination(2 examples below) to make into a MTF nothing works.

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

Can someone help me out??
---------------------------------------

Example:
def hma = wma(2 * (wma(src, length / 2) (period = time))- (wma(src, length), round(sqrt(length))(period = time)));

Eaxmple:
def hma = wma(period = time)(2 * wma(period = time)(src(period = time), length / 2) - wma(period = time)(src(period = time), length), round(period = time)(sqrt(period = time)(length)));

Try this

Ruby:
input agg = AggregationPeriod.FIVE_MIN...

SleepyZ

Well-known member
VIP
Lifetime
This is the orig main script for the Hull Suite Ive been trying every combination(2 examples below) to make into a MTF nothing works.

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

Can someone help me out??
---------------------------------------

Example:
def hma = wma(2 * (wma(src, length / 2) (period = time))- (wma(src, length), round(sqrt(length))(period = time)));

Eaxmple:
def hma = wma(period = time)(2 * wma(period = time)(src(period = time), length / 2) - wma(period = time)(src(period = time), length), round(period = time)(sqrt(period = time)(length)));

Try this

Ruby:
input agg = AggregationPeriod.FIVE_MIN;
input len = 20;

def price = close(period=agg);

plot HMA  = WMA(2 * WMA(price, len / 2) - WMA( price, len), Sqrt(len));
HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));
 
Solution

halcyonguy

Well-known member
VIP
Lifetime
This is the orig main script for the Hull Suite Ive been trying every combination(2 examples below) to make into a MTF nothing works.

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

Can someone help me out??
---------------------------------------

Example:
def hma = wma(2 * (wma(src, length / 2) (period = time))- (wma(src, length), round(sqrt(length))(period = time)));

Eaxmple:
def hma = wma(period = time)(2 * wma(period = time)(src(period = time), length / 2) - wma(period = time)(src(period = time), length), round(period = time)(sqrt(period = time)(length)));


hi @SleepyZ looks like we tackled this one about the same time. heh

because the plot uses 2nd agg data , there will be horizontal sections of the line, which will have the down color.

----------------------------------

i have seen problems with several 2nd agg functions within a formula, so i separated them out. maybe it's only an issue when they are of different times.

-----------------------------------

there may be a couple of possibilities for why you don't see a plot.

..thinkscript doesn't like formulas that try to calculate 2+ values from (different) 2nd aggregation(s).
it is best to separate the formulas, to calculate the value for each 2nd agg item.
then combine those variables into a final formula. this is what i did.

..there may be an error in your formulas. but we won't know, because you didn't post your complete code.
i don't know what you have set up for time =


this plots a stepped line. there are horizontal sections.
because of this i added a variable called dir, that is used to drive the plot color.


Ruby:
def na = double.nan;
def bn = barnumber();

input agg1 = AggregationPeriod.DAY;
def cls_agg1 = close(period = agg1);

input wma_len1 = 20;

# set vars for 1 and 2
def wma1 = wma(cls_agg1, floor(wma_len1 / 2));
def wma2 = wma(cls_agg1, wma_len1);

# do the final wma of the prev 2
#  def hma = wma(2 * wma1(src, length / 2) - wma2(src, length), round(sqrt(length)));
def lenx = floor( sqrt( wma_len1));
def wmamtf = wma( ((2 * wma1) - wma2)  , lenx);

# direction, use for plot color
def dir = if bn == 1 then 0
  else if wmamtf > wmamtf[1] then 1
  else if wmamtf < wmamtf[1] then -1
  else dir[1];

plot z9 = wmamtf;
z9.AssignValueColor(if dir > 0 then color.green else color.red);

#-----------------------------------

input test2_bubbles = no;
addchartbubble(test2_bubbles, low, 
wma1 + " 1\n" +
wma2 + " 2\n" +
wmamtf + " 3"
, color.yellow, no);

input test1 = no;
plot z1 = if test1 then wma1 else na;
plot z2 = if test1 then wma2 else na;
#
#

V8LG5Bm.jpg
 

JP782

Active member
Heres what I have... it works for most part
makes odd redlines when its green

2RhNYOM.png



Code:
input length = 60; #Length(180-200 for floating S/R , 55 for swing entry)

input switchColor = yes; #Color Hull according to trend?

input candleCol = NO; #Color candles based on Hull's Trend?

input cloudSwitch = yes; #Show as a Band?

input thicknesSwitch = 1; #Line Thickness

input price= close; 

input time= aggregationPeriod.FIVE_MIN;


# (period = time)


def na = Double.NaN;



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


# 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(!cloudSwitch);


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


def condHull = HULL > HULL[2];

def Five = if condHull and !condHull[1] then close(period = AggregationPeriod.FIVE_MIN) else double.Nan;

plot bullish = close == close(period = AggregationPeriod.FIVE_MIN) and !Isnan(Five);

bullish.SetPaintingStrategy(PaintingStrategy.Boolean_ARROW_UP);

bullish.SetDefaultColor(color.DARK_ORANGE);

bullish.setlineweight(5);
 

cpntexas

New member
MTF can be a great thing, or not so great in TOS due to the "feature" you are running into in the above solution. I have created quite a number of TOS MTF versions of indicators like MACD Stochastics and Moving averages. Those odd portions of your line are where the aggregation has only some subset [ in the example below a 1:6 ratio], of the data shown in your base timeframe and hence fills in with those aggravating flat spots during those spaces it has no data bars. You can only get a revelation of the next bar in the higher timeframe every X bars of the lower, everything in between is non determinable and hence flat lines or extensions of the last known

Example: If you have a 20 hull ma on a 5minutes and would like to see the 30minute hull 20 an alternate solution for smoother lines than above using the AgggregationPeriod is to do the following:
On a 5 minute chart plot a 20HMA, then on a separate 30 minute chart plot a 20 HMA.
Observe the value on the 30 minute 20 HMA for reference.
Then plot a 120 HMA on the 5 minute chart, the results will be very close to the value observed on the 30 min 20HMA, and difference caused by the lack of data points inside the 30 minute bars that would be closing data points in the 5min bar. This 120 count is derived by the result of dividing Higher Timeframe (30) by the Lower Timeframe (5) = 6, and then multiplying this result (6) by the HMA bar count you want to represent from the Higher Timeframe (20) and results in 120 HMA on the 5 minute chart.
Just a way to get a very close approximate when needing to determine a Higher Timeframe line direction w/out being noisy due to the AggregationPeriod jagged results
 

JP782

Active member
MTF can be a great thing, or not so great in TOS due to the "feature" you are running into in the above solution. I have created quite a number of TOS MTF versions of indicators like MACD Stochastics and Moving averages. Those odd portions of your line are where the aggregation has only some subset [ in the example below a 1:6 ratio], of the data shown in your base timeframe and hence fills in with those aggravating flat spots during those spaces it has no data bars. You can only get a revelation of the next bar in the higher timeframe every X bars of the lower, everything in between is non determinable and hence flat lines or extensions of the last known

Example: If you have a 20 hull ma on a 5minutes and would like to see the 30minute hull 20 an alternate solution for smoother lines than above using the AgggregationPeriod is to do the following:
On a 5 minute chart plot a 20HMA, then on a separate 30 minute chart plot a 20 HMA.
Observe the value on the 30 minute 20 HMA for reference.
Then plot a 120 HMA on the 5 minute chart, the results will be very close to the value observed on the 30 min 20HMA, and difference caused by the lack of data points inside the 30 minute bars that would be closing data points in the 5min bar. This 120 count is derived by the result of dividing Higher Timeframe (30) by the Lower Timeframe (5) = 6, and then multiplying this result (6) by the HMA bar count you want to represent from the Higher Timeframe (20) and results in 120 HMA on the 5 minute chart.
Just a way to get a very close approximate when needing to determine a Higher Timeframe line direction w/out being noisy due to the AggregationPeriod jagged results
Uhhhh that went right over my head
 

Speeds

New member
http://tos.mx/9xfxFN8
https://tos.mx/NWbQ0lW


Here's a couple HMA Strategy Grids I tweaked code I got on this site. The p&l was about $30M/year on /NQ daily chart. I'm studying trying to learn thinkscript. I never coded before a couple months ago till I found this forum. I'm not sure how to post screenshot yet.

Code:
# ########################################################
# TOS HullMovingAVg
input HMA1Length = 10;
input HMA2Length = 20;
input Price = HL2;
input displace = 2;

plot HMA1 = MovingAverage(AverageType.HULL, Price, HMA1Length); #12
plot HMA2 = MovingAverage(AverageType.HULL, Price, HMA2Length)[-displace]; #89

def HMA1up = HMA1 > HMA1[1];
def HMA2up = HMA2 > HMA2[1];
plot HMAup = HMA1up and HMA2up ;

def HMA1dn = HMA1 < HMA1[1];
def HMA2dn = HMA2 < HMA2[1];
plot HMAdn = HMA1dn and HMA2dn ;


HMA1.SetLineWeight(2);
HMA1.DefineColor("Positive", Color.BLUE);
HMA1.DefineColor("Negative", Color.YELLOW);
HMA1.AssignValueColor(if HMA1 > HMA1[1] then HMA1.Color("Positive") else HMA1.Color("Negative"));

HMA2.SetLineWeight(2);
HMA2.DefineColor("Positive", Color.GREEN);
HMA2.DefineColor("Negative", Color.RED);
HMA2.AssignValueColor(if HMA2 > HMA2[1] then HMA2.Color("Positive") else HMA2.Color("Negative"));


AddOrder(OrderType.BUY_TO_OPEN, HMA1 crosses above HMA1[1]);
AddOrder(OrderType.SELL_TO_CLOSE, HMA1 crosses below HMA1[1]);
AddOrder(OrderType.BUY_TO_CLOSE, HMA2 crosses above HMA2[1]);
AddOrder(OrderType.SELL_TO_OPEN, HMA2 crosses below HMA2[1]);


Code:
#Hull_MA_Strategy
input price = close;
input length = 12;
input displace = 3;

plot HMA1 = MovingAverage(AverageType.HULL, price, length);
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"));

HMA1.DefineColor("Bullish", GetColor(1));
HMA1.DefineColor("Bearish", GetColor(0));
HMA1.AssignValueColor(if HMA > HMA[1] then HMA.Color("Bullish") else HMA1.Color("Bearish"));
AssignPriceColor(if HMA > HMA[1] then HMA.Color("Bullish") else HMA.Color("Bearish"));
AddOrder(OrderType.BUY_TO_OPEN, HMA crosses above HMA[1]);
AddOrder(OrderType.SELL_TO_CLOSE, HMA crosses below HMA[1]);
AddOrder(OrderType.SELL_TO_OPEN, HMA crosses below HMA[1]);
AddOrder(OrderType.BUY_TO_CLOSE, HMA crosses above HMA[1]);
 
Last edited:

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top