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 #####
 

Similar threads

Top