VDub_HMA_Trading_Bands For ThinkOrSwim

henry1224

Expert
VIP
Lifetime
Code:
#Converted from Trading View VDub HMA trading Bands V2 by H enry Kaczmarczyk
#use with Heiken ASHI Bars
Declare Upper;
Input Length1 = 34;
Input Length2 = 21;
Input Arrows = no;
input Dotsize = 3;
Plot HMAClose = wma(2*WMA(Close,Length2/2) – WMA(Close,Length2),Round(Sqrt(Length2)));
HMAClose.setdefaultColor(Color.yellow);
Plot HMAHigh = wma(2*WMA(High,Length1/2) – WMA(High,Length1),Round(Sqrt(Length1)));
HMAHigh.setdefaultColor(Color.Cyan);
Plot HMALow = wma(2*WMA(Low,Length1/2) – WMA(Low,Length1),Round(Sqrt(Length1)));
HMALow.setdefaultColor(Color.Magenta);
AddCloud(HMAClose , HMAHigh,Color.Cyan,Color.Black);
AddCloud(HMAClose , HMALow,Color.Black,Color.Magenta);

plot ArrowDown = if arrows and (HMAClose Crosses below HMAHigh) then HMAHigh else double.nan;
ArrowDown.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown.setDefaultColor(color.Cyan);
ArrowDown.setLineWeight(dotsize);

plot ArrowUp = if arrows and (HMAClose  crosses above HMALow ) then HMALow else double.nan;
ArrowUp.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp.setDefaultColor(color.Magenta);
ArrowUp.setLineWeight(dotsize);

plot ArrowDown2 = if arrows and (HMAClose Crosses below HMALow) then HMALow else double.nan;
ArrowDown2.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown2.setDefaultColor(color.Yellow);
ArrowDown2.setLineWeight(dotsize +1);

plot ArrowUp2 = if arrows and (HMAClose  crosses above HMAHigh ) then HMAHigh else double.nan;
ArrowUp2.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp2.setDefaultColor(color.Yellow);
ArrowUp2.setLineWeight(dotsize+1);
 
Here is conversion of Vdub_HMA_Bands_V2 for ThinkorSwim. I add band colors to it in order to follow the trends.

Code:
#Converted from Trading View VDub HMA trading Bands V2 by H enry Kaczmarczyk
#use with Heiken ASHI Bars
Declare Upper;
Input Length1 = 34;
Input Length2 = 21;
Input Arrows = no;
input Dotsize = 3;
Plot HMAClose = wma(2*WMA(Close,Length2/2) – WMA(Close,Length2),Round(Sqrt(Length2)));
HMAClose.setdefaultColor(Color.yellow);
Plot HMAHigh = wma(2*WMA(High,Length1/2) – WMA(High,Length1),Round(Sqrt(Length1)));
HMAHigh.setdefaultColor(Color.Cyan);
Plot HMALow = wma(2*WMA(Low,Length1/2) – WMA(Low,Length1),Round(Sqrt(Length1)));
HMALow.setdefaultColor(Color.Magenta);
AddCloud(HMAClose , HMAHigh,Color.Cyan,Color.Black);
AddCloud(HMAClose , HMALow,Color.Black,Color.Magenta);

plot ArrowDown = if arrows and (HMAClose Crosses below HMAHigh) then HMAHigh else double.nan;
ArrowDown.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown.setDefaultColor(color.Cyan);
ArrowDown.setLineWeight(dotsize);

plot ArrowUp = if arrows and (HMAClose  crosses above HMALow ) then HMALow else double.nan;
ArrowUp.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp.setDefaultColor(color.Magenta);
ArrowUp.setLineWeight(dotsize);

plot ArrowDown2 = if arrows and (HMAClose Crosses below HMALow) then HMALow else double.nan;
ArrowDown2.setpaintingStrategy(paintingStrategy.Arrow_Down);
ArrowDown2.setDefaultColor(color.Yellow);
ArrowDown2.setLineWeight(dotsize +1);

plot ArrowUp2 = if arrows and (HMAClose  crosses above HMAHigh ) then HMAHigh else double.nan;
ArrowUp2.setpaintingStrategy(paintingStrategy.Arrow_Up);
ArrowUp2.setDefaultColor(color.Yellow);
ArrowUp2.setLineWeight(dotsize+1);
https://www.tradingview.com/script/ONqyIYrK-Vdub-HMA-Bands-V2/

Ruby:
#https://www.tradingview.com/script/ONqyIYrK-Vdub-HMA-Bands-V2/

input length = 18;
def src = high;
def nan  =  Double.NaN;
def hullma = wma(2*wma(src, length/2)-wma(src, length), round(sqrt(length)));
plot Upperband =hullma;
input fill = yes;
input length2 = 18;
def src2 = low;
def hullma2 = wma(2*wma(src2, length2/2)-wma(src2, length2), round(sqrt(length2)));
plot lowerband = hullma2;
input length3 = 21;
def src3 = close;
def hullma3 = wma(2*wma(src3, length3/2)-wma(src3, length3), round(sqrt(length3)));
plot midline =hullma3;
def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);
def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;

DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));
 
Last edited:
Smoothed Hull Moving Averages.
Ruby:
#https://usethinkscript.com/threads/fw_mobo_advanced-indicator.10525/
input showpricecolor = no;
input price = high;
input length = 5;
def nan  =  Double.NaN;
input fill = yes;
def smooth = 2 / (length + 1);
def emas = HullMovingAvg(price, length) * (1 + smooth) -
           (HullMovingAvg(HullMovingAvg(price, length)) * smooth);
def emasp = HullMovingAvg(emas, length);
plot Data = emasp;
 input price1 = low;
def smooth1 = 2 / (length + 1);
def emas1 = HullMovingAvg(price1, length) * (1 + smooth1) -
           (HullMovingAvg(HullMovingAvg(price1, length)) * smooth1);
def emas1p = HullMovingAvg(emas1, length);
plot Data1 =  emas1p ;
plot LowerBand = emas1p;
plot UpperBand = emasp;
def mid = (UpperBand + LowerBand) / 2;
plot Midline = mid;
def a = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def b = (UpperBand < UpperBand[1] and LowerBand < LowerBand[1]);
def c = (UpperBand > UpperBand[1] and Midline > Midline[1]);
def d = (UpperBand < UpperBand[1] and midline < midline[1]);
def e = average(close)>midline;
def f = midline<average(close);
def Chg      =   If(a, 1, If(b, -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def Chg_a      =   If((c or e), 1, If((d or f), -1, 0));
def Hold_a     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
def MBUP     =   if fill and Hold[0] == 1 then midline else nan;
def MBDn     =   if fill and Hold[0] == -1 then Midline else nan;
DefineGlobalColor("Cloud Up", Color.red);
DefineGlobalColor("Cloud_Up", Color.downtick);
DefineGlobalColor("Cloud_Dn", Color.light_green);
DefineGlobalColor("Cloud Dn", Color.cyan);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
AddCloud(MBUp, UBUp, GlobalColor("Cloud_Up"), GlobalColor("Cloud_Dn"));
AddCloud(MBDn, UBDn, GlobalColor("Cloud_Dn"), GlobalColor("Cloud_Up"));
 
Last edited:
I removed the middle line from the indicator.
Ruby:
#https://usethinkscript.com/threads/fw_mobo_advanced-indicator.10525/
input showpricecolor = no;
input price = high;
input length = 5;
def nan  =  Double.NaN;
input fill = yes;
def smooth = 2 / (length + 1);
def emas = HullMovingAvg(price, length) * (1 + smooth) -
           (HullMovingAvg(HullMovingAvg(price, length)) * smooth);
def emasp = HullMovingAvg(emas, length);
plot Data = emasp;
 input price1 = low;
def smooth1 = 2 / (length + 1);
def emas1 = HullMovingAvg(price1, length) * (1 + smooth1) -
           (HullMovingAvg(HullMovingAvg(price1, length)) * smooth1);
def emas1p = HullMovingAvg(emas1, length);
plot Data1 =  emas1p ;
plot LowerBand = emas1p;
plot UpperBand = emasp;
def Chg      =   If((UpperBand > UpperBand[1] and LowerBand > LowerBand[1]), 1, If((UpperBand < UpperBand[1] and LowerBand < LowerBand[1]), -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
DefineGlobalColor("Cloud Up", Color.magenta);
DefineGlobalColor("Cloud Dn", Color.green);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
 
Last edited:
I removed the middle line from the indicator.
Ruby:
#https://usethinkscript.com/threads/fw_mobo_advanced-indicator.10525/
input showpricecolor = no;
input price = high;
input length = 5;
def nan  =  Double.NaN;
input fill = yes;
def smooth = 2 / (length + 1);
def emas = HullMovingAvg(price, length) * (1 + smooth) -
           (HullMovingAvg(HullMovingAvg(price, length)) * smooth);
def emasp = HullMovingAvg(emas, length);
plot Data = emasp;
 input price1 = low;
def smooth1 = 2 / (length + 1);
def emas1 = HullMovingAvg(price1, length) * (1 + smooth1) -
           (HullMovingAvg(HullMovingAvg(price1, length)) * smooth1);
def emas1p = HullMovingAvg(emas1, length);
plot Data1 =  emas1p ;
plot LowerBand = emas1p;
plot UpperBand = emasp;
def Chg      =   If((UpperBand > UpperBand[1] and LowerBand > LowerBand[1]), 1, If((UpperBand < UpperBand[1] and LowerBand < LowerBand[1]), -1, 0));
def Hold     =   CompoundValue(1, If(Hold[1] == Chg or Chg == 0, Hold[1], If(Chg == 1, 1, -1)), 0);
def LBUp     =   if fill and Hold[0] == 1 then lowerBand else nan;
def UBUp     =   if fill and Hold[0] == 1 then upperband else nan;
def LBDn     =   if fill and Hold[0] == -1 then lowerband else nan;
def UBDn     =   if fill and Hold[0] == -1 then upperband else nan;
DefineGlobalColor("Cloud Up", Color.magenta);
DefineGlobalColor("Cloud Dn", Color.green);
AddCloud(LBUp, UBUp, GlobalColor("Cloud Up"), GlobalColor("Cloud Dn"));
AddCloud(LBDn, UBDn, GlobalColor("Cloud Dn"), GlobalColor("Cloud Up"));
In my version, I used the Middle band as the timing signal , when the Middle line crossed above or below a band line. The Middle line has a faster length than the outer bands
 
In my version, I used the Middle band as the timing signal , when the Middle line crossed above or below a band line. The Middle line has a faster length than the outer bands
There are two versions with and without middle line in my converted indicators for the readers to choose. I also used smoothed Hull moving averages instead of Hull moving averages.
 
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
220 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