• LIMITED TIME OFFER: use coupon code PRIMEDAY (case sensitive) at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22. Biggest discount this year!

Hull Moving Average ATR Bands for ThinkorSwim

Namor

New member
VIP
Wondering if anyone has coded the Hull Range Indicator...(it positions the ATR above and below the Hull MA -creating an envelope)?
 

rad14733

Well-known member
VIP
@Namor I thought I had the code but am not finding it... I used to use the Hull Moving Average exclusively but switched to EMA's some months ago... Shouldn't be too difficult to code... I'll take another look because I swear I had written it last year...
 

rad14733

Well-known member
VIP
@Namor I went ahead and re-coded the HMA bands similar to what I tried last year... I added the ability to optionally have the bands show trend the same as the HMA itself... Hopefully, this is what you were looking for... I didn't add the ability to change the number of ATR's but it would be an easy addition if desired... Let me know what you think...

Ruby:
# HMA_ATR_Bands
# Based on standard HullMovigAvg - TD Ameritrade IP Company, Inc. (c) 2008-2021
# Modified to include ATR bands by rad14733
# ATR bands can optionally be painted the same trend colors as the HMA
# v1.0 : 2021-02-22 : Initial Code

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"));

input useHMABandColors = yes;

def atr = ATR();

plot ATRupperBand = HMA + atr;
ATRupperBand.SetPaintingStrategy(PaintingStrategy.LINE);
ATRupperBand.SetDefaultColor(Color.WHITE);
ATRupperBand.AssignValueColor(if useHMABandColors then if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down") else Color.CURRENT);
ATRupperBand.SetLineWeight(1);


plot ATRlowerBand = HMA - atr;
ATRlowerBand.SetPaintingStrategy(PaintingStrategy.LINE);
ATRlowerBand.SetDefaultColor(Color.WHITE);
ATRlowerBand.AssignValueColor(if useHMABandColors then if HMA > HMA[1] then HMA.color("Up") else HMA.color("Down") else Color.CURRENT);
ATRlowerBand.SetLineWeight(1);

#END - HMA_ATR_Bands

With HMA Trend Bands

DoljF4h.png


Without HMA Trend Bands

Pa1p7mJ.png
 
Last edited:

scott69

Member
I wrote this to create ATR bands around the closing price. You can add the Hull code in there and have it work around that.

Code:
# Plot ATR Bands

input aggregationPeriod = AggregationPeriod.DAY;
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def close = close(period = aggregationPeriod);

input length = 10;
input averageType = AverageType.WILDERS;
input StopFactor = 2;


def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);

plot line1 = close + (ATR*StopFactor);
plot line2 = close - (ATR*StopFactor);

##### End Code #####
 

Jonas99

Active member
VIP
I wrote this to create ATR bands around the closing price. You can add the Hull code in there and have it work around that.

Code:
# Plot ATR Bands

input aggregationPeriod = AggregationPeriod.DAY;
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def close = close(period = aggregationPeriod);

input length = 10;
input averageType = AverageType.WILDERS;
input StopFactor = 2;


def ATR = MovingAverage(averageType, TrueRange(high, close, low), length);

plot line1 = close + (ATR*StopFactor);
plot line2 = close - (ATR*StopFactor);

##### End Code #####
Can you show a picture of the ATR band? and time frame? I imported your script but nothing showed up on all time frame tested.
 

Mac Trader

New member
@rad14733 can this variable MA code be converted to TOS?

//
// @author LazyBear
// List of all my indicators:
// https://docs.google.com/document/d/15AGCufJZ8CIUvwFJ9W-IKns88gkWOKBCvByMEvm5MLo/edit?usp=sharing
//
study(title="Variable Moving Average [LazyBear]", shorttitle="VMA_LB", overlay=true)
src=close
l =input(6, title="VMA Length")
std=input(false, title="Show Trend Direction")
bc=input(false, title="Color bars based on Trend")
k = 1.0/l
pdm = max((src - src[1]), 0)
mdm = max((src[1] - src), 0)
pdmS = ((1 - k)*nz(pdmS[1]) + k*pdm)
mdmS = ((1 - k)*nz(mdmS[1]) + k*mdm)
s = pdmS + mdmS
pdi = pdmS/s
mdi = mdmS/s
pdiS = ((1 - k)*nz(pdiS[1]) + k*pdi)
mdiS = ((1 - k)*nz(mdiS[1]) + k*mdi)
d = abs(pdiS - mdiS)
s1 = pdiS + mdiS
iS = ((1 - k)*nz(iS[1]) + k*d/s1)
hhv = highest(iS, l)
llv = lowest(iS, l)
d1 = hhv - llv
vI = (iS - llv)/d1
vma = (1 - k*vI)*nz(vma[1]) + k*vI*src
vmaC=(vma > vma[1]) ? green : (vma<vma[1]) ? red : (vma==vma[1]) ? blue : black
plot(vma, color=std?vmaC:black, linewidth=3, title="VMA")
barcolor(bc?vmaC:na)
 

rad14733

Well-known member
VIP
@Mac Trader You never posted a link to the original source of the code, nor did you post an image of it... We don't generally just convert code from other platforms based on one members request unless the coder is interested in the end result themselves... Conversions take time and effort because functions and associated logic needs to be looked up for both platforms to convert the code...

Have you tried the TOS built-in VariableMA...??? What makes this one so different...??? A link and image would be helpful if you're looking to garner interest... We shouldn't be required to go track it down ourselves...
 

Mac Trader

New member
@Mac Trader You never posted a link to the original source of the code, nor did you post an image of it... We don't generally just convert code from other platforms based on one members request unless the coder is interested in the end result themselves... Conversions take time and effort because functions and associated logic needs to be looked up for both platforms to convert the code...

Have you tried the TOS built-in VariableMA...??? What makes this one so different...??? A link and image would be helpful if you're looking to garner interest... We shouldn't be required to go track it down ourselves...
Sorry. https://www.tradingview.com/script/6Ix0E5Yr-Variable-Moving-Average-LazyBear/ Picture is in the link.
 

Similar threads

Top