ATR Volatility Based System Indicator for ThinkorSwim

@skynetgen To clarify - on a 5 min chart you are setting the agg period to 15 min?
yep. on 30m to 4h and on daily to weekly

Latest version. Added pullback entry dot which is integrated with scan code (2/-2 - pullback entry)
https://tos.mx/fAmwq9V
overall this is very good volatility based indicator. However there are 2 things I am currently discovered which compliments it very well:
namely momentum indicators. I presently use HHLLS with (12 length, HULL settings) as leading confirmation and Rev engineered RSI upper channels as main momentum guide

All makes perfect sense - volatility indicates phase of price action. Momentum - the actual price action strength and direction confirming action inside this phase
 
@skynetgen Thanks for improving this indicator. I tested this in few charts. I felt it worked best in combination with RSI-Laguerre With Fractal Energy. You can find it here (I discovered in this forum itself). RSI Lag is very good in showing early signs of Trend. Check and tell us your opinion.

https://tos.mx/nmdvUNS
If you have made any updates this, please share with us.

Few questions -
1. What is HHLLS? You mentioned it couple of times.
2. You mentioned
on 30m to 4h and on daily to weekly

I didn't follow this part, can you please explain what you mean?
 
Folks - for those interested here is HHLLS study, read the notes for further details

Code:
# HHLLS
# blt
# 4.28.2016

# Here is a new TOS indicator that was in S&C Trader's Tips, but has not been made part of the native TOS studies list yet. 
# It is working very well on my 1min chart with the length of 8. The only other change to the indicator that I made was to add the cloud. 

declare lower;

input length = 20;
input over_bought = 60;
input signal_line = 50;
input over_sold = 10;
input averageType = AverageType.EXPONENTIAL;

Assert(length > 1, "'length' must be greater than one: " + length);

def HH = if high > high[1] then (high - Lowest(high, length)) / (Highest(high, length) - Lowest(high, length)) else 0;
def LL = if low < low[1] then (Highest(low, length) - low) / (Highest(low, length) - Lowest(low, length)) else 0;

plot HHS = 100 * MovingAverage(averageType, HH, length);
plot LLS = 100 * MovingAverage(averageType, LL, length);
plot OverBought = over_bought;
plot SignalLine = signal_line;
plot OverSold = over_sold;

HHS.SetDefaultColor(GetColor(6));
LLS.SetDefaultColor(GetColor(5));
OverBought.SetDefaultColor(GetColor(7));
SignalLine.SetDefaultColor(GetColor(7));
OverSold.SetDefaultColor(GetColor(7));

addcloud(hhs,lls,color.green,color.red);

# End Study
 
I don't use this study but had saved this study some time ago as it looked interesting
Don't see any reason why it would not work on higher agg
For reference the author likes to trade a 1 min chart and thus this is probably why reference is made to 1 min agg in his notes
 
Found this interesting script on TradingView. I think it's based on Jim Berg's ATR Volatility Based System.

cxGHUrq.png

gQ7TRQ9.png


thinkScript Code

Code:
# ATR Volatility Based System Jim Berg
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/UxWO2H5P/

input length = 10;

def EntrySignal = close > (lowest(low, 20) + 2 * atr(Length));
def ExitSignal = close < (highest(high, 20) - 2 * atr(Length));
def TrailStop = highest(close - 2 * atr(Length), 15);
def ProfitTaker = expAverage(high, 13) + 2 * atr(Length);

assignPriceColor(if EntrySignal then Color.GREEN else if ExitSignal then Color.RED else Color.WHITE);

def entry = ((lowest(low, 20)) + 2 * atr(Length));
def exit = ((highest(high, 20)) - 2 * atr(Length));
plot trail = TrailStop;
plot profit_taker = ProfitTaker;

trail.SetDefaultColor(GetColor(0));
profit_taker.SetDefaultColor(GetColor(1));

AddCloud(entry, exit, color.yellow, color.yellow);
Is there a MTF indicator for this one?
 
So I think I found a perfect MTF compliment for this. This is based on hguru CCIATRMTF cloud (fixed a few bugs and simplified a bit)
using 15min for 5min and 4h for 30m

https://tos.mx/T8ikSO8
This indicator is really excellent. However, today the arrows stopped showing up on some futures and equity charts. I can still look at the crossovers for the signals but I like the arrows. They make it easier to read the chart. The arrows work on SPY and QQQ but don't work on /ES or AAPL. Any idea why?

Here's the code:
Code:
# SuperTrend CCI ATR Based on  hguru | Paris | BLT
input agg = AggregationPeriod.MIN;
def c = close(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def pricedata = hl2(period = agg);

input show_cloud = yes;
input show_entryarrows = yes;

DefineGlobalColor("TrendUp", CreateColor(0, 102, 255));# CreateColor(0, 255, 255));
DefineGlobalColor("TrendDown",color.dark_orange);# CreateColor(0, 102, 255));

#============================= SuperTrend 2016 ===========================#
#==================== Translation for TOS by Syracusepro =================#
input Factor = 1.3; #hint Factor: supertrend ATR factor. /n influences ST and cloud
input Pd = 20; #hint PD: supertrend atr
input Lookback = 3; #hint Lookback: supertrend lookback delay

def atr_st = Average(TrueRange(h, c, l), Pd);
def Up = pricedata[Lookback] - (Factor * atr_st);
def Dn = pricedata[Lookback] + (Factor * atr_st);
def TrendUp = if c > TrendUp[1] then Max(Up, TrendUp[1]) else Up;
def TrendDown = if c < TrendDown[1] then Min(Dn, TrendDown[1]) else Dn;
def Trend = if c > TrendDown[1] then 1 else if c < TrendUp[1] then -1 else (Trend[1]);
def Trendbn = if c > TrendDown[1] then BarNumber() else if c < TrendUp[1] then BarNumber() else (Trendbn[1]);
def Trendc = if c > TrendDown[1] then c else if c < TrendUp[1] then c else (Trendc[1]);

plot Tsl = if Trend == 1 then TrendUp else TrendDown;
Tsl.AssignValueColor(if Trend == 1 then GlobalColor("TrendUp") else GlobalColor("TrendDown"));
Tsl.SetLineWeight(1);

plot entryArrow = (if Trend == 1 and Trend[1] == -1 then First(Trendbn) else Double.NaN); #Up Entry Arrow
entryArrow.SetDefaultColor(Color.CYAN);entryArrow.setLineWeight(3);
entryArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
entryArrow.SetHiding(!show_entryarrows);

plot exitArrow = (if Trend == -1 and Trend[1] == 1 then First(Trendbn) else Double.NaN); #Down Entry Arrow
exitArrow.SetDefaultColor(Color.LIGHT_ORANGE);exitArrow.setLineWeight(3);
exitArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
exitArrow.SetHiding(!show_entryarrows);

#========================== End SuperTrend 2016 ===========================#
# CCI_ATR Trendline
# Mobius | Syracusepro
# Chat room request 01.28.2016
# 10.31.2018

# CCI is a study that measures distance from the mean. This study plots
# a trend line based on that distance using ATR as the locator for the line.

input lengthCCI = 20;
input lengthATR = 4;
input AtrFactor = 0.7;

def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;
def price = c + l + h;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
          then 0
          else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if isnan(close[1]) then close
          else if CCI > 0
          then Max(MT1[1], pricedata - ATRcci)
          else Min(MT1[1], pricedata + ATRcci);
plot CCIATR = if MT1>0 then MT1 else pricedata; # fix for MT1
CCIATR.AssignValueColor(if c < MT1 then Color.RED else Color.GREEN);#TAKEN FROM SUPERTREND

# End Code CCI_ATR Trend
########################################################
# Cloud Combo Additions
# Ghost / Hguru
# 2.3.2019
# checks supertrend relative CCIATR

def ComboUpTrend = CCIATR > Tsl;
def ComboDnTrend = CCIATR < Tsl;
def crossup = ComboUpTrend == 1 and ComboUpTrend[1] <> 1;
def crossdn = ComboDnTrend == 1 and ComboDnTrend[1] <> 1;

AddCloud(if show_cloud and ComboUpTrend == 1 then CCIATR
             else Double.NaN, if show_cloud and ComboUpTrend then Tsl
             else Double.NaN, GlobalColor("TrendUp"), GlobalColor("TrendUp"));
AddCloud(if show_cloud and ComboDnTrend == 1 then Tsl
             else Double.NaN, if show_cloud and ComboDnTrend == 1 then CCIATR
             else Double.NaN, GlobalColor("TrendDown"), GlobalColor("TrendDown"));
 
This indicator is really excellent. However, today the arrows stopped showing up on some futures and equity charts. I can still look at the crossovers for the signals but I like the arrows. They make it easier to read the chart. The arrows work on SPY and QQQ but don't work on /ES or AAPL. Any idea why?

Here's the code:
Code:
# SuperTrend CCI ATR Based on  hguru | Paris | BLT
input agg = AggregationPeriod.MIN;
def c = close(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def pricedata = hl2(period = agg);

input show_cloud = yes;
input show_entryarrows = yes;

DefineGlobalColor("TrendUp", CreateColor(0, 102, 255));# CreateColor(0, 255, 255));
DefineGlobalColor("TrendDown",color.dark_orange);# CreateColor(0, 102, 255));

#============================= SuperTrend 2016 ===========================#
#==================== Translation for TOS by Syracusepro =================#
input Factor = 1.3; #hint Factor: supertrend ATR factor. /n influences ST and cloud
input Pd = 20; #hint PD: supertrend atr
input Lookback = 3; #hint Lookback: supertrend lookback delay

def atr_st = Average(TrueRange(h, c, l), Pd);
def Up = pricedata[Lookback] - (Factor * atr_st);
def Dn = pricedata[Lookback] + (Factor * atr_st);
def TrendUp = if c > TrendUp[1] then Max(Up, TrendUp[1]) else Up;
def TrendDown = if c < TrendDown[1] then Min(Dn, TrendDown[1]) else Dn;
def Trend = if c > TrendDown[1] then 1 else if c < TrendUp[1] then -1 else (Trend[1]);
def Trendbn = if c > TrendDown[1] then BarNumber() else if c < TrendUp[1] then BarNumber() else (Trendbn[1]);
def Trendc = if c > TrendDown[1] then c else if c < TrendUp[1] then c else (Trendc[1]);

plot Tsl = if Trend == 1 then TrendUp else TrendDown;
Tsl.AssignValueColor(if Trend == 1 then GlobalColor("TrendUp") else GlobalColor("TrendDown"));
Tsl.SetLineWeight(1);

plot entryArrow = (if Trend == 1 and Trend[1] == -1 then First(Trendbn) else Double.NaN); #Up Entry Arrow
entryArrow.SetDefaultColor(Color.CYAN);entryArrow.setLineWeight(3);
entryArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
entryArrow.SetHiding(!show_entryarrows);

plot exitArrow = (if Trend == -1 and Trend[1] == 1 then First(Trendbn) else Double.NaN); #Down Entry Arrow
exitArrow.SetDefaultColor(Color.LIGHT_ORANGE);exitArrow.setLineWeight(3);
exitArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
exitArrow.SetHiding(!show_entryarrows);

#========================== End SuperTrend 2016 ===========================#
# CCI_ATR Trendline
# Mobius | Syracusepro
# Chat room request 01.28.2016
# 10.31.2018

# CCI is a study that measures distance from the mean. This study plots
# a trend line based on that distance using ATR as the locator for the line.

input lengthCCI = 20;
input lengthATR = 4;
input AtrFactor = 0.7;

def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;
def price = c + l + h;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
          then 0
          else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if isnan(close[1]) then close
          else if CCI > 0
          then Max(MT1[1], pricedata - ATRcci)
          else Min(MT1[1], pricedata + ATRcci);
plot CCIATR = if MT1>0 then MT1 else pricedata; # fix for MT1
CCIATR.AssignValueColor(if c < MT1 then Color.RED else Color.GREEN);#TAKEN FROM SUPERTREND

# End Code CCI_ATR Trend
########################################################
# Cloud Combo Additions
# Ghost / Hguru
# 2.3.2019
# checks supertrend relative CCIATR

def ComboUpTrend = CCIATR > Tsl;
def ComboDnTrend = CCIATR < Tsl;
def crossup = ComboUpTrend == 1 and ComboUpTrend[1] <> 1;
def crossdn = ComboDnTrend == 1 and ComboDnTrend[1] <> 1;

AddCloud(if show_cloud and ComboUpTrend == 1 then CCIATR
             else Double.NaN, if show_cloud and ComboUpTrend then Tsl
             else Double.NaN, GlobalColor("TrendUp"), GlobalColor("TrendUp"));
AddCloud(if show_cloud and ComboDnTrend == 1 then Tsl
             else Double.NaN, if show_cloud and ComboDnTrend == 1 then CCIATR
             else Double.NaN, GlobalColor("TrendDown"), GlobalColor("TrendDown"));
Having Problems? Does the MTF indicator appear to be not working or partially working when you load the study onto your chart?
A common error when using MTF indicators is trying to use a time frame that is lower than the chart you are posting it on. On the TOS platform, you can display data from a higher timeframe onto a lower timeframe but not the other way around.
https://tlc.thinkorswim.com/center/...hapter-11---Referencing-Secondary-Aggregation
 
This indicator is really excellent. However, today the arrows stopped showing up on some futures and equity charts. I can still look at the crossovers for the signals but I like the arrows. They make it easier to read the chart. The arrows work on SPY and QQQ but don't work on /ES or AAPL. Any idea why?
Unfortunately your default MTF setting is set to the lowest time frame of 1 min. If you view a higher time frame it will not work. Simply change the code to get the current time frame and make it non MTF or change the default MTF time frame something like 15m / or change in the indicator options to 15 and set as default then you can view 5min and it will work fine on 1 min even.
 
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
351 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