Hull Format, Label, Watchlist, Scan for ThinkorSwim

I was wondering if there was a scanner out there that alerted you when if using say the hma 25 and hma 49 when they cross each other? Any help would be appreciated
 
I was wondering if there was a scanner out there that alerted you when if using say the hma 25 and hma 49 when they cross each other? Any help would be appreciated
You can easily create one in the Scan tab:

TaWCmPr.png


Which gives the resulting Thinkscript code if you're happier that way:

Code:
HullMovingAvg("length" = 25) crosses above HullMovingAvg("length" = 49)

This is, of course, for the 25 crossing above the 49.

-mashume
 
I am wanting to modify this script to use when two Hull MAs Cross each other and send me an Alert. can someone help with the change This code works but needs to be changed to two Hull MAs crosses Thank you guys.

Code:
input EMAPeriod = 10;
input SMAPeriod = 13;
input price = close;
def na = double.nan;
plot fastema = ExpAverage(price, EMAPeriod);
plot slowema = Average(price, SMAPeriod);
def crossover = if fastema > slowema AND fastema[1] <= slowema[1] then 1 else 0;
def crossunder = if fastema < slowema AND fastema[1] >= slowema[1] then 1 else 0;
#Plot arrows
Plot up = if crossover then low - tickSize() else na;
Plot down = if crossunder then high + tickSize() else na;
up.SetPaintingStrategy(paintingStrategy.ARROW_UP);
down.SetPaintingStrategy(paintingStrategy.ARROW_DOWN);
#Trigger alerts
alert(crossover[1], "Crossover", Alert.Bar, Sound.Ding);
alert(crossunder[1], "Crossunder", Alert.Bar, Sound.Ding);

it would also be nice to get a "Time level" vertical slotted line as an output for the cross

This could be even better to convert to a Hull cross as it has the Vertical Line output.

Code:
# E-Charts v2
declare upper;
input short_average = 5;
input medium_average = 10;
input long_average = 20;
input average_type = {default "SMA", "EMA"};
input show_vertical_line = no;
input show_bubble_labels = yes;
def MA1;
def MA2;
def MA3;
switch (average_type) {
case "SMA":
MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
MA3 = Average(close, long_average);
case "EMA":
MA1 = ExpAverage(close, short_average);
MA2 = ExpAverage(close, medium_average);
MA3 = ExpAverage(close, long_average);
}
# define e-signal and crossover point
def Eup = MA1 > MA2 && MA2 > MA3;
def Edn = MA1 < MA2 && MA2 < MA3;
def CrossUp = close > MA1 && Eup && !Eup[1];
def CrossDn = close < MA1 && Edn && !Edn[1];
# Define up and down signals
def higherHigh = close > Highest(max(open,close), 3)[1];
def lowerLow = close < Lowest(min(open,close), 3)[1];
def SignalUp = if (CrossUp && higherHigh)
then 1
else if (CrossUp[1] && higherHigh && !higherHigh[1])
then 1
else if (CrossUp[2] && higherHigh && !higherHigh[1] && !higherHigh[2])
then 1
else Double.NaN;
def SignalDn = if (CrossDn && lowerLow)
then 1
else if (CrossDn[1] && lowerLow && !lowerLow[1])
then 1
else if (CrossDn[2] && lowerLow && !lowerLow[1] && !lowerLow[2])
then 1
else Double.NaN;

# Plot the moving average lines
plot ln1 = MA1;
ln1.SetDefaultColor(CreateColor(145, 210, 144));
ln1.SetLineWeight(2);
plot ln2 = MA2;
ln2.SetDefaultColor(CreateColor(111, 183, 214));
ln2.SetLineWeight(2);
plot ln3 = MA3;
ln3.SetDefaultColor(CreateColor(249, 140, 182));
ln3.SetLineWeight(2);

# Draw vertical line to indicate call and put signals
AddVerticalLine(SignalUp && show_vertical_line, "Up", Color.UPTICK);
AddVerticalLine(SignalDn && show_vertical_line, "Down", Color.LIGHT_RED);
# Show Call / Put Signal in a Chart Bubble
AddChartBubble(SignalUp && show_bubble_labels, low - 0.3, "Up", Color.UPTICK, no);
AddChartBubble(SignalDn && show_bubble_labels, high + 0.3, "Dn", Color.LIGHT_RED);
# Add label for Eup or Edn
AddLabel(Eup, "E Up", Color.GREEN);
AddLabel(Edn, "E Dn", Color.RED);
# Alerts
Alert(CrossUp, " ", Alert.Bar, Sound.Chimes);
Alert(CrossDn, " ", Alert.Bar, Sound.Bell);
 
Last edited by a moderator:
Has anyone made a version of this that can be set to multiple time frames? I have tried and failed - I am very much a beginner with ThinkScript. Just wondering if anyone else has given it a shot more successfully than I have.
 
@westgl This is your second code you posted, I slightly modified the switch statement to use HMA's as well. Check if it does what you want -
Code:
# E-Charts v2
declare upper;
input short_average = 5;
input medium_average = 10;
input long_average = 20;
input average_type = {default "SMA", "EMA", "HMA"};
input show_vertical_line = no;
input show_bubble_labels = yes;
def MA1;
def MA2;
def MA3;
switch (average_type) {
case "SMA":
MA1 = Average(close, short_average);
MA2 = Average(close, medium_average);
MA3 = Average(close, long_average);
case "EMA":
MA1 = ExpAverage(close, short_average);
MA2 = ExpAverage(close, medium_average);
MA3 = ExpAverage(close, long_average);
case "HMA":
MA1 = HullMovingAvg(close, short_average);
MA2 = HullMovingAvg(close, medium_average);
MA3 = HullMovingAvg(close, long_average);
}
# define e-signal and crossover point
def Eup = MA1 > MA2 && MA2 > MA3;
def Edn = MA1 < MA2 && MA2 < MA3;
def CrossUp = close > MA1 && Eup && !Eup[1];
def CrossDn = close < MA1 && Edn && !Edn[1];
# Define up and down signals
def higherHigh = close > Highest(max(open,close), 3)[1];
def lowerLow = close < Lowest(min(open,close), 3)[1];
def SignalUp = if (CrossUp && higherHigh)
then 1
else if (CrossUp[1] && higherHigh && !higherHigh[1])
then 1
else if (CrossUp[2] && higherHigh && !higherHigh[1] && !higherHigh[2])
then 1
else Double.NaN;
def SignalDn = if (CrossDn && lowerLow)
then 1
else if (CrossDn[1] && lowerLow && !lowerLow[1])
then 1
else if (CrossDn[2] && lowerLow && !lowerLow[1] && !lowerLow[2])
then 1
else Double.NaN;

# Plot the moving average lines
plot ln1 = MA1;
ln1.SetDefaultColor(CreateColor(145, 210, 144));
ln1.SetLineWeight(2);
plot ln2 = MA2;
ln2.SetDefaultColor(CreateColor(111, 183, 214));
ln2.SetLineWeight(2);
plot ln3 = MA3;
ln3.SetDefaultColor(CreateColor(249, 140, 182));
ln3.SetLineWeight(2);

# Draw vertical line to indicate call and put signals
AddVerticalLine(SignalUp && show_vertical_line, "Up", Color.UPTICK);
AddVerticalLine(SignalDn && show_vertical_line, "Down", Color.LIGHT_RED);
# Show Call / Put Signal in a Chart Bubble
AddChartBubble(SignalUp && show_bubble_labels, low - 0.3, "Up", Color.UPTICK, no);
AddChartBubble(SignalDn && show_bubble_labels, high + 0.3, "Dn", Color.LIGHT_RED);
# Add label for Eup or Edn
AddLabel(Eup, "E Up", Color.GREEN);
AddLabel(Edn, "E Dn", Color.RED);
# Alerts
Alert(CrossUp, " ", Alert.Bar, Sound.Chimes);
Alert(CrossDn, " ", Alert.Bar, Sound.Bell);


@bcnhill The below code was taken from this post, and edited to add multi-timeframe capability -
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
# 2020.08.10 3.0 Pensar - Added multi-timeframe input

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 aggregation = aggregationperiod.FIVE_MIN;

def src = close(period = aggregation); #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
 
Last edited:
Hi all, my apologies for bothering.

I recently started using the Hull Moving Average in ToS and noticed that on other charting platforms/brokers, the values for a bar's HMA are different. For example, on intraday charts for /ES (1 min for example), the values have a difference of up to .5 in value and in bigger timeframes (daily for example), that skew can go up to 3 points in difference. Is there a specific reason as to why this is? I looked into the source of the HMA in ThinkScript but could not find a specific formula; it only brings up MovingAverage(AverageType.Hull). The explanation of this indicator on the TLC ToS website shows the regular explanation on how the HMA for a value is calculated, but does not show a specific formula (in script, that is). As far as I've tested, other platforms use the same theoretical formula for their HMA calculations but still result in different values. I'd like to keep using the ToS version of this indicator, therefore, I'd like to ask, is it possible to extract the exact formula that ToS uses to calculate its HMA values for each bar?
 
Here is the source code for the HullMovingAvg indicator in ToS:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2020
#

input price = close;
input length = 20;
input displace = 0;

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

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));
 
AHA!!! I discovered the issue:

I had coded my error function to use a period of 16 by default, which happens to be an even square ( sqrt(16) = 4 ). Here, I've changed the default period to 17, and suddenly there is visible error:

Code:
input period = 17;
declare lower;

def hmaFullPeriod = MovingAverage(AverageType.WEIGHTED, close, period);
def hmaHalfPeriod = MovingAverage(AverageType.WEIGHTED, close, period / 2);
def fltBandPass = hmaHalfPeriod - hmaFullPeriod;
def hmaRough = fltBandPass + hmaHalfPeriod;
def hmaSmoothed = MovingAverage(AverageType.WEIGHTED, hmaRough, RoundDown(Sqrt(period), 0));

def ToS_HMA = MovingAverage(AverageType.HULL, close, 17);

def errHMA = hmaSmoothed - ToS_HMA;
plot HMA = errHMA;

Alan Hull specifies that the period for the final smoothing is the square root of the chosen period, which in most cases will yield a non-integer value; not allowed as the period in any moving average. To correct for this, Mr. Hull uses truncation - that is, he simply cuts off the decimal portion and uses only the integer. This can be done in many languages by using the Int() function, or in thinkScript by using the RoundDown() function. I used RoundDown() to calculate HMA, which means that if you use a square period (such as 16), there will be no error evident in the ToS version. But if you use a non-square period (such as 17), there will be error ---- If, ToS uses Round() instead of RoundDown() in it's internal (hidden) calculation of HMA.

Therefore, I declare that ToS has erroneously coded HMA using Round() instead of RoundDown() and is not always going to be accurate. This is quite a revelation for me, as I have created a number of indicators and strategies using the ToS HMA, and now I see that they may be suffering from this inaccuracy issue. @MovingAvenue - if the error in the ToS HMA is a problem for you, I suggest you use my HMA indicator instead (please clean up the ratty code!) for a more accurate result.
 
OK, I couldn't help myself... here is short, sweet code with more inputs and color changes - should serve as a direct replacement for the ToS HMA, but without the error:

Code:
#True HMA by MoneyMagnet

input price = close;
input length = 20;
input displace = 0;

plot HMA = MovingAverage(AverageType.WEIGHTED, 2 * MovingAverage(AverageType.WEIGHTED, price, RoundDown(length / 2)) - MovingAverage(AverageType.WEIGHTED, price, length), RoundDown(Sqrt(length), 0))[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));
 
I sent in a white paper here a while ago (and have no idea where it is on this site) that details and ranks how the major moving averages are calculated and react to various markets. You may want to consider finding it and reviewing it.
 
Code:
#Follow @Krose_TDA on twitter for updates to this and other custom columns
#TD Ameritrade IP Company, Inc. (c) 2008-2019
#Follow @Krose_TDA on twitter for updates to this and other custom columns
#Input desired parameters using the input statements below

input price = close;
input length = 20;
input WithinBars = 1;

def hma = HullMovingAvg(price,length);

def TriglableBull = hma[1]<hma[2] and hma>hma[1];
def TriglableBear = hma[1]>hma[2]and hma < hma[1];
def trigger = TriglableBear or TriglableBull;

addlabel(yes,if triglableBear then "bear" else if TriglableBull then "Bull" else " ");

Can one of you coders please modify this code to have the words "bear" show in red and "bull" show in green in the watchlist column. I don't want it to show continuously. I messed around with this for a while and cannot figure it out. I.m ready to through the computer into the front yard!

I will never be a coder, don't have the patients, have great respect for all you coders.

Thank you for all you do!
 
@farresa Add this snippet to the bottom of your script:

Code:
AssignbackgroundColor(if triglableBear then color.dark_red else if TriglableBull then color.dark_green else color.gray);
 
@diazlaz See if this concept is workable. Idealy, to me, SPY should be at ==0 with the others rotating around it. Thoughts?
@BenTen Please copy this to its own thread...
Code:
# beta_rotation_v2
#ETF_Rotate_Lower_ED_nn 4-2019
# from 4/4/2019 chat room:
# 06:37 Mobius: johnny - To find rotation quickly - Use primary ETF's in a watchlist with 2 columns first column is Correlation to SPX second is a stochastic of Beta, if Beta is 1 or close to 1 that ETF is moving at the fastest momentum in that range and if correlation is with SPX .85 or better it's moving with SPX cor# daily start with 13,34 as starting point
#markos #took out out Beta 1 & 2 4-19-19 # Put Back in 6-23-19

declare lower;

input BetaLength = 21;
input StochLength =34;
input showBeta = No;
input showOverlay = Yes;

input Cyclicals      = "XLY";
input Technology     = "XLK";
input Industrials    = "XLI";
input Materials      = "XLB";
input Energy         = "XLE";
input Staples        = "XLP";
input HealthCare     = "XLV";
input Utilities      = "XLU";
input Financials     = "XLF";

#------------------------------
#----purple colors
defineglobalColor(“PlumMedium“, createColor(221, 160, 221));
defineglobalColor(“Orchid“, createColor(218, 130, 214));
defineglobalColor(“MediumOrchid“, createColor(186, 85, 211));
defineglobalColor(“MediumPurple“, createColor(147, 112, 219));
defineglobalColor(“DarkOrchid“, createColor(153, 50, 204));


plot Scriptlabel = Double.NaN;
Scriptlabel.SetDefaultColor(CreateColor (0, 0, 0));

def Agg = GetAggregationPeriod();

#--------------------date start
addLabel(1,  getMonth() + "/" +
             getDayOfMonth(getYyyyMmDd()) + "/" +
             AsPrice(getYear()), GlobalColor("PlumMedium"));
#--------------------date end

#addLabel(1, " Ticker: '" + GetSymbol() + "' ", GlobalColor("Orchid"));

addLabel(1, "Agg: " +
              ( if Agg == 60000 then "1 Min"
           else if Agg == 120000 then "2 Min"
           else if Agg == 180000 then "3 Min"
           else if Agg == 240000 then "4 Min"
           else if Agg == 300000 then "5 Min"
           else if Agg == 600000 then "10 Min"
           else if Agg == 900000 then "15 Min"
           else if Agg == 1800000 then "30 Min"
           else if Agg == 3600000 then "1 Hour"
           else if Agg == 7200000 then "2 Hour"
           else if Agg == 14400000 then "4 Hours"
           else if Agg == 86400000 then "1 Day"
           else if Agg == 604800000 then "1 Week"
           else if Agg == 2592000000 then "1 Month"
           else  (Agg / 1000 / 60) + "Minutes")  +
           " (" + (if Agg<=23400000
                   then 23400000/Agg
                   else 86400000/Agg)+ ")"
          , GlobalColor("MediumPurple"));
#addLabel(1, BarNumber() + " Bars", GlobalColor("DarkOrchid"));

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

addLabel(1,"Rotation Beta/Stochastic (" + betaLength + "," +stochLength + ") ", color.Light_Gray);


script calcBeta {
  input secondSymbol = "XLF";
  input refSymbol = "SPX";
  input betaLength = 21;
  input returnLength = 1;

  def refPrice = close(refSymbol);
  def primary = if refPrice[returnLength] == 0
                then 0
                else (refPrice - refPrice[returnLength]) /
                      refPrice[returnLength] * 100;
  def secondPrice = close(secondSymbol);
  def secondary = if secondPrice[returnLength] == 0
                  then 0
                  else (secondPrice - secondPrice[returnLength]) /
                        secondPrice[returnLength] * 100;
  plot Beta = covariance(secondary, primary, betaLength) /
                         Sqr(stdev(primary, betaLength));
}

script EhlersESSfilter {
    input price = close;
    input length = 8;
    def ESS_coeff_0 = Exp(-Double.Pi * Sqrt(2) / length);
    def ESS_coeff_2 = 2 * ESS_coeff_0 * Cos(Sqrt(2) * Double.Pi / length);
    def ESS_coeff_3 = - Sqr(ESS_coeff_0);
    def ESS_coeff_1 = 1 - ESS_coeff_2 - ESS_coeff_3;
    def ESS_filter = if IsNaN(price + price[1]) then
                      ESS_filter[1]
                 else ESS_coeff_1 * (price + price[1]) / 2 +
                      ESS_coeff_2 * ESS_filter[1] +
                      ESS_coeff_3 * ESS_filter[2];
    plot Smooth_Filter =
         if barnumber() <  length then
              price
         else if !IsNaN(price) then
              ESS_filter
         else Double.NaN;
}

script calcStoch {
  input data = close;
  input StochLength = 21;
  def stochasticValue = ((data - lowest(data, StochLength)) /
                         (highest(data, StochLength) - lowest(data, StochLength)));
  plot stoch = stochasticValue;
}

plot beta1 = if showBeta then calcBeta(Cyclicals) else Double.NaN;
plot beta2 = if showBeta then calcBeta(Technology) else Double.NaN;
####
plot stoch1 = calcStoch(
                        data = EhlersESSfilter(
                               calcBeta(secondSymbol = Cyclicals,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);
stoch1.SetDefaultColor(Color.VIOLET);
stoch1.SetLineWeight(2);
stoch1.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
stoch1.HideBubble();
AddLabel(ShowOverlay, " Cyclicals ", Color.VIOLET);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch1 < 0.15 then 0 else if stoch1 > 0.85 then 1 else stoch1, "Cyclicals", Color.VIOLET, stoch1 > 0.5);

plot stoch2 = calcStoch(
                        data = EhlersESSfilter(
                               calcBeta(secondSymbol = Technology,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);
stoch2.SetDefaultColor(CreateColor(90, 160, 120));
stoch2.SetLineWeight(5);
stoch2.SetStyle(Curve.LONG_DASH);
stoch2.HideBubble();
AddLabel(ShowOverlay, " Techology ", CreateColor(90, 160, 120));
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch2 < 0.15 then 0 else if stoch2 > 0.85 then 1 else stoch2, "Technology", CreateColor(90, 160, 120), stoch2 > 0.5);

plot stoch3 = calcStoch(
                        data = EhlersESSfilter(
                               calcBeta(secondSymbol = Industrials,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);
stoch3.SetDefaultColor(Color.MAGENTA);
stoch3.SetLineWeight(5);
stoch3.SetStyle(Curve.SHORT_DASH);
stoch3.HideBubble();
AddLabel(ShowOverlay, " Industrials ", Color.MAGENTA);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch3 < 0.15 then 0 else if stoch3 > 0.85 then 1 else stoch3, "Industrials", Color.MAGENTA, stoch3 > 0.5);

plot stoch4 = calcStoch(
                        data = EhlersESSfilter(
                               calcBeta(secondSymbol = Materials,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);
stoch4.SetDefaultColor(Color.CYAN);
stoch4.SetLineWeight(2);
stoch4.SetPaintingStrategy(PaintingStrategy.LINE);
stoch4.HideBubble();
AddLabel(ShowOverlay, " Materials ", Color.CYAN);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch4 < 0.15 then 0 else if stoch4 > 0.85 then 1 else stoch4, "Materials", Color.CYAN, stoch4 > 0.5);

plot stoch5 = calcStoch(
                        data = EhlersESSfilter(
                               calcBeta(secondSymbol = Energy,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);
stoch5.SetDefaultColor(Color.YELLOW);
stoch5.SetLineWeight(1);
stoch5.SetPaintingStrategy(PaintingStrategy.Line_vs_POINTS);
stoch5.HideBubble();
AddLabel(ShowOverlay, " Energy ", Color.YELLOW);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch5 < 0.15 then 0 else if stoch5 > 0.85 then 1 else stoch5, "Energy", Color.YELLOW, stoch5 > 0.5);

plot stoch6 = calcStoch(
                        data = EhlersESSfilter(
                               calcBeta(secondSymbol = Staples,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);
stoch6.SetDefaultColor(CreateColor(80, 180, 70));
stoch6.SetLineWeight(2);
stoch6.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
stoch6.HideBubble();
AddLabel(ShowOverlay, " Staples ", CreateColor(80, 180, 70));
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch6 < 0.15 then 0 else if stoch6 > 0.85 then 1 else stoch6, "Staples", CreateColor(80, 180, 70), stoch6 > close);

plot stoch7 = calcStoch(
                        data = EhlersESSfilter(
                               calcBeta(secondSymbol = HealthCare,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);
stoch7.SetDefaultColor(CreateColor(180, 80, 180));
stoch7.SetLineWeight(4);
stoch7.SetPaintingStrategy(PaintingStrategy.LINE);
stoch7.HideBubble();
AddLabel(ShowOverlay, " HealthCare ", CreateColor(180, 80, 180));
AddChartBubble("time condition" = ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), "price location" = if stoch7 < 0.15 then 0 else if stoch7 > 0.85 then 1 else stoch7, text = "HealthCare", color = CreateColor(180, 80, 180), stoch7 > 0.5);

plot stoch8 = calcStoch(
                        data = EhlersESSfilter(
                               calcBeta(secondSymbol = Utilities,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);
stoch8.SetDefaultColor(Color.ORANGE);
stoch8.SetLineWeight(2);
stoch8.SetPaintingStrategy(PaintingStrategy.LINE);
stoch8.HideBubble();
AddLabel(ShowOverlay, " Utilities ", Color.ORANGE);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close[0]), if stoch8 < 0.15 then 0 else if stoch8 > 0.85 then 1 else stoch8, "Utilities", Color.ORANGE, stoch8 > 0.5);

plot stoch9 = calcStoch(
                        data = EhlersESSfilter(
                               calcBeta(secondSymbol = Financials,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);
stoch9.SetDefaultColor(Color.PINK);
stoch9.SetLineWeight(2);
stoch9.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
stoch9.HideBubble();
AddLabel(ShowOverlay, " Financials ", Color.PINK);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch9 < 0.15 then 0 else if stoch9 > 0.85 then 1 else stoch9, "Financials", Color.PINK, stoch9 > 0.5);

#----------------------------------------------
def barNumber = BarNumber();
def endBar = if !IsNaN(close) and IsNaN(close[-1]) then barNumber else endBar[1];
def lastBar = HighestAll(endBar);
input flowLabelStep = 40;
addLabel(1,"Last Bar = " + lastBar, color.Light_Gray);
DefineGlobalColor("YellowGreen", CreateColor(90, 140, 5));
AddChartBubble(barNumber == (lastBar - flowLabelStep), 1.01,
"M O N E Y   F L O W S   I N", globalColor("YellowGreen"), 1);
AddChartBubble(barNumber == (lastBar - 2*flowLabelStep), 1.01,
"M O N E Y   F L O W S   I N", globalColor("YellowGreen"), 1);
#mAddChartBubble(barNumber == (lastBar - 3*flowLabelStep), 1.01,
#"M O N E Y   F L O W S   I N", globalColor("YellowGreen"), 1);

DefineGlobalColor("Cinamon", CreateColor(200, 10, 40));
AddChartBubble(barNumber == (lastBar - flowLabelStep), -0.01,
"M O N E Y   F L O W S   O U T", globalColor("Cinamon"), 0);
AddChartBubble(barNumber == (lastBar - 2*flowLabelStep), -0.01,
"M O N E Y   F L O W S   O U T", globalColor("Cinamon"), 0);
#mAddChartBubble(barNumber == (lastBar - 3*flowLabelStep), -0.01,
#m"M O N E Y   F L O W S   O U T", globalColor("Cinamon"), 0);

#plot zero = if isNaN(close) then double.nan else 0;
plot zero = if barNumber > (lastBar + 7) then double.nan else 0;
zero.SetDefaultColor(createColor(90, 20, 20));
zero.SetStyle(Curve.Long_Dash);
zero.SetLineWeight(5);
zero.HideBubble();
plot one = if barNumber > (lastBar + 7) then double.nan else 1;
one.SetDefaultColor(createColor(20, 70, 20));
one.SetStyle(Curve.Long_Dash);
one.SetLineWeight(5);
one.HideBubble();
#EOC

SectorRotate_ED_NN

Dsy0J1F.png
Hi, is it possible to add the ev and pot sector? thx
 
Code:
 declare lower;
#100 * (h / AVGC200)
def x=100 * (high / Average(length = 200, data = CLOSE));

 
input length =10;
def displace = 0;

plot HMA = MovingAverage(AverageType.wEIGHTED, x, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));
 
@Piper2808t
Ruby:
input agg = AggregationPeriod.THIRTY_MIN ;
def c = close(period = agg);
def h = high(period = agg);


 declare lower;
#100 * (h / AVGC200)
def x=100 * (h / Average(length = 200, data = c));

 
input length =10;
def displace = 0;

plot HMA = MovingAverage(AverageType.wEIGHTED, x, length)[-displace];

HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down"));
 
Need help.
I am using 1 min and 10 min time frame. For 10 mins chart, I am using a hull moving average with 8 period. How to get a auto price level line with the hull moving average? which is also going to show on my 1 min chart?


Thanks so much!!!!!!!!!!!!!!!!!!
 
Need help.
I am using 1 min and 10 min time frame. For 10 mins chart, I am using a hull moving average with 8 period. How to get a auto price level line with the hull moving average? which is also going to show on my 1 min chart?


Thanks so much!!!!!!!!!!!!!!!!!!

This has an option to plot or not the actual hull moving average line and/or plot a horizontal line across the chart at last bar's price level of the
HMA.
Capture.jpg
Ruby:
input show_hma_plot = no;
input agg = AggregationPeriod.TEN_MIN;
input len = 8;
plot hma8 = HullMovingAvg(close(period = agg), len);
hma8.SetHiding(!show_hma_plot);

#Hull MovingAverage Price Level
input show_hma_price_level = yes;
def last_hma8_bn   = HighestAll(if !IsNaN(close) and IsNaN(close[-1]) then BarNumber() else 0);
def last_hma8_pr   = HighestAll(if BarNumber() == last_hma8_bn
                     then hma8
                     else Double.NaN);
plot last_hma8     = (last_hma8_pr);
last_hma8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
last_hma8.SetDefaultColor(Color.CYAN);
last_hma8.SetHiding(!show_hma_price_level);
 
Here you go!

Chart Behavior

RQ4nGUX.png


Watchlist:

r7fQNw7.png


Ruby:
#Follow @Krose_TDA on twitter for updates to this and other custom columns
#TD Ameritrade IP Company, Inc. (c) 2008-2019
#Follow @Krose_TDA on twitter for updates to this and other custom columns
#Input desired parameters using the input statements below
#
#2019.10.11 - @diazlaz - Updated to include persist state
#

input price = close;
input length = 20;
input WithinBars = 1;

def hma = HullMovingAvg(price,length);

def TriglableBull = hma[1]<hma[2] and hma>hma[1];
def TriglableBear = hma[1]>hma[2]and hma < hma[1];
def trigger = TriglableBear or TriglableBull;
def sTrigger = if TriglableBear then -100 else if TriglableBull then 100 else sTrigger[1];

AddLabel(yes,
if sTrigger == -100 then "Bear" else "Bull",
if sTrigger == -100 then COLOR.RED  else COLOR.GREEN
);

#plot results = sTrigger;
Hey man,

any chance to share your candles colors rules? gonna help me a lot! If not, its ok!!

Thanks in advance.
 
Hey man,

any chance to share your candles colors rules? gonna help me a lot! If not, its ok!!

Thanks in advance.
if hull ma of previous candle is less than hull ma of two candles ago and the hull ma is greater than hull ma of the previous candle then green else if opposite then red.

Which is the thinkscript syntax for saying if the Hull Moving Average was falling and now it is rising then color.green else red.
Rich (BB code):
input price = close;
input length = 20;
input WithinBars = 1;

def hma = HullMovingAvg(price,length);

def TriglableBull = hma[1]<hma[2] and hma>hma[1];
def TriglableBear = hma[1]>hma[2]and hma < hma[1];
def trigger = TriglableBear or TriglableBull;

addlabel(yes,if triglableBear then "bear" else if TriglableBull then "Bull" else " ");
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
380 Online
Create Post

Similar threads

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.
Back
Top