ATR Cloud Levels for ThinkorSwim

Status
Not open for further replies.

Welkin

Active member
The author of the study isn't available on the forum to provide answers to questions. So this thread has been locked.

Think I might've posted a older version of something similar I'd made in the past, but couldn't find it... figured I'd post this one because it's far less intrusive on a chart, especially when you have other indicators on top of it.
Plots ATR Levels above and below the day's open to a max of 2x ATR in quarter segments.

hodskxV.png



Code:
#[email protected]
#Plots Upper and Lower ATR ranges onto the current day's open

def NA = Double.NaN;

input atrLength = 14;
input averageType = AverageType.WILDERS;
input showClouds = yes;
input showAtrLabel = yes;
input showAtrStatsLabel = yes;

#ATR
def TR1 = high("period"= AggregationPeriod.DAY) - low("period"= AggregationPeriod.DAY);
def TR2 = AbsValue(high("period"= AggregationPeriod.DAY) - close("period"= AggregationPeriod.DAY)[1]);
def TR3 = AbsValue(low("period"= AggregationPeriod.DAY) - close("period"= AggregationPeriod.DAY)[1]);
def TrueRange = if TR1 > TR2 and TR1 > TR3 then TR1 else if TR2 > TR1 and TR2 > TR3 then TR2 else TR3;
def ATR = MovingAverage(averageType, TrueRange, atrLength);
def DayHigh = high("period"= AggregationPeriod.DAY);
def DayLow = low("period"= AggregationPeriod.DAY);
def Range = DayHigh - DayLow;
#PLOTS
plot DayOpen = open("period"= AggregationPeriod.DAY);
plot ATRQuarterH = DayOpen + (ATR[1]/4);
plot ATRQuarterL = DayOpen - (ATR[1]/4);
plot ATRHalfH = DayOpen + (ATR[1]/2);
plot ATRHalfL = DayOpen - (ATR[1]/2);
plot ATR3QuarterH = DayOpen + (ATR[1]*.75);
plot ATR3QuarterL = DayOpen - (ATR[1]*.75);
plot ATRFullH = DayOpen + (ATR[1]);
plot ATRFullL = DayOpen - (ATR[1]);
plot ATRFullQuarterH = DayOpen + (ATR[1]*1.25);
plot ATRFullQuarterL = DayOpen - (ATR[1]*1.25);
plot ATRFullHalfH = DayOpen + (ATR[1]*1.5);
plot ATRFullHalfL = DayOpen - (ATR[1]*1.5);
plot ATRFull3QuarterH = DayOpen + (ATR[1]*1.75);
plot ATRFull3QuarterL = DayOpen - (ATR[1]*1.75);
plot ATRFull2xH = DayOpen + (ATR[1]*2);
plot ATRFull2xL = DayOpen - (ATR[1]*2);


#LABEL
AddLabel(if showAtrLabel then 1 else 0, "ATR: " + Round(ATR,2) + " / Range: " + Round(Range,2) + " / " + Round(Range/ATR,2) +"xATR", Color.GRAY);



#CLOUDS
AddCloud(if !showClouds then NA else ATRFull2xH, ATRFull3QuarterH, CreateColor(160,160,160),CreateColor(160,160,160), no);
AddCloud(if !showClouds then NA else ATRFull3QuarterH, ATRFullHalfH, CreateColor(140,140,140),CreateColor(140,140,140), no);
AddCloud(if !showClouds then NA else ATRFullHalfH, ATRFullQuarterH, CreateColor(120,120,120),CreateColor(120,120,120), no);
AddCloud(if !showClouds then NA else ATRFullQuarterH, ATRFullH, CreateColor(100,100,100),CreateColor(100,100,100), no);
AddCloud(if !showClouds then NA else ATRFullH, ATR3QuarterH, CreateColor(80,80,80),CreateColor(80,80,80), no);
AddCloud(if !showClouds then NA else ATR3QuarterH, ATRHalfH, CreateColor(60,60,60),CreateColor(60,60,60), no);
AddCloud(if !showClouds then NA else ATRHalfH, ATRQuarterH, CreateColor(40,40,40),CreateColor(40,40,40), no);

AddCloud(if !showClouds then NA else ATRFull3QuarterL, ATRFull2xL, CreateColor(160,160,160),CreateColor(160,160,160), no);
AddCloud(if !showClouds then NA else ATRFullHalfL, ATRFull3QuarterL, CreateColor(140,140,140),CreateColor(140,140,140), no);
AddCloud(if !showClouds then NA else ATRFullQuarterL, ATRFullHalfL, CreateColor(120,120,120),CreateColor(120,120,120), no);
AddCloud(if !showClouds then NA else ATRFullL, ATRFullQuarterL, CreateColor(100,100,100),CreateColor(100,100,100), no);
AddCloud(if !showClouds then NA else ATR3QuarterL, ATRFullL, CreateColor(80,80,80),CreateColor(80,80,80), no);
AddCloud(if !showClouds then NA else ATRHalfL, ATR3QuarterL, CreateColor(60,60,60),CreateColor(60,60,60), no);
AddCloud(if !showClouds then NA else ATRQuarterL, ATRHalfL, CreateColor(40,40,40),CreateColor(40,40,40), no);

#FORMATTING
#ATRQuarterH.Hide();
#ATRQuarterL.Hide();
#ATRHalfH.Hide();
#ATRHalfL.Hide();
#ATR3QuarterH.Hide();
#ATR3QuarterL.Hide();
#ATRFullH.Hide();
#ATRFullL.Hide();
#ATRFullQuarterH.Hide();
#ATRFullQuarterL.Hide();
#ATRFullHalfH.Hide();
#ATRFullHalfL.Hide();
#ATRFullHalfH.Hide();
#ATRFullHalfL.Hide();
#ATRFullHalfH.Hide();
#ATRFullHalfL.Hide();
#ATRFull3QuarterH.Hide();
#ATRFull3QuarterL.Hide();
#ATRFull2xH.Hide();
#ATRFull2xL.Hide();

DayOpen.SetDefaultColor(Color.WHITE);
DayOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRQuarterH.SetDefaultColor(Color.DARK_GRAY);
ATRQuarterL.SetDefaultColor(Color.DARK_GRAY);
ATRQuarterH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRQuarterL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRHalfH.SetDefaultColor(Color.DARK_GRAY);
ATRHalfL.SetDefaultColor(Color.DARK_GRAY);
ATRHalfH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRHalfL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATR3QuarterH.SetDefaultColor(Color.DARK_GRAY);
ATR3QuarterL.SetDefaultColor(Color.DARK_GRAY);
ATR3QuarterH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATR3QuarterL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRFullH.SetDefaultColor(Color.DARK_GRAY);
ATRFullL.SetDefaultColor(Color.DARK_GRAY);
ATRFullH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRFullL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRFullQuarterH.SetDefaultColor(Color.DARK_GRAY);
ATRFullQuarterL.SetDefaultColor(Color.DARK_GRAY);
ATRFullQuarterH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRFullQuarterL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRFullHalfH.SetDefaultColor(Color.DARK_GRAY);
ATRFullHalfL.SetDefaultColor(Color.DARK_GRAY);
ATRFullHalfH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRFullHalfL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRFull3QuarterH.SetDefaultColor(Color.DARK_GRAY);
ATRFull3QuarterL.SetDefaultColor(Color.DARK_GRAY);
ATRFull3QuarterH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRFull3QuarterL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRFull2xH.SetDefaultColor(Color.DARK_GRAY);
ATRFull2xL.SetDefaultColor(Color.DARK_GRAY);
ATRFull2xH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRFull2xL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Edit: cleaned up the calculations
 
Last edited by a moderator:
How do you use this, what's the strategy behind it long or short?
I use this as a way to determine whether a stock is potentially exhausted in a certain direction, or look for a reversal play, depending on the time of day it manages to reach that full ATR level. typically if a stock moves a full ATR (4 quarter segments in the indicator) early in the day, you can try and make a play off a reversal. How you decide to use it is up to you. I recommend using it in combination with other indicators that show deviations in price movements such as Bollinger Bands, VWAP deviations, etc..
 
great script Think I might've posted a older version of something similar I'd made in the past, but couldn't find it... figured I'd post this one because it's far less intrusive on a chart, especially when you have other indicators on top of it.
Plots ATR Levels above and below the day's open to a max of 2x ATR in quarter segments.

hodskxV.png

https://tos.mx/RVicBnG

Code:
#[email protected]
#Plots Upper and Lower ATR ranges onto the current day's open

def NA = Double.NaN;

input atrLength = 14;
input averageType = AverageType.WILDERS;
input showClouds = yes;
input showAtrLabel = yes;
input showAtrStatsLabel = yes;

#ATR
def TR1 = high("period"= AggregationPeriod.DAY) - low("period"= AggregationPeriod.DAY);
def TR2 = AbsValue(high("period"= AggregationPeriod.DAY) - close("period"= AggregationPeriod.DAY)[1]);
def TR3 = AbsValue(low("period"= AggregationPeriod.DAY) - close("period"= AggregationPeriod.DAY)[1]);
def TrueRange = if TR1 > TR2 and TR1 > TR3 then TR1 else if TR2 > TR1 and TR2 > TR3 then TR2 else TR3;
def ATR = MovingAverage(averageType, TrueRange, atrLength);
def DayHigh = high("period"= AggregationPeriod.DAY);
def DayLow = low("period"= AggregationPeriod.DAY);
def Range = DayHigh - DayLow;
#PLOTS
plot DayOpen = open("period"= AggregationPeriod.DAY);
plot ATRQuarterH = DayOpen + (ATR[1]/4);
plot ATRQuarterL = DayOpen - (ATR[1]/4);
plot ATRHalfH = DayOpen + (ATR[1]/2);
plot ATRHalfL = DayOpen - (ATR[1]/2);
plot ATR3QuarterH = DayOpen + (ATR[1]/2) + (ATR[1]/4);
plot ATR3QuarterL = DayOpen - (ATR[1]/2) - (ATR[1]/4);
plot ATRFullH = DayOpen + (ATR[1]);
plot ATRFullL = DayOpen - (ATR[1]);
plot ATRFullQuarterH = DayOpen + (ATR[1]) + (ATR[1]/4);
plot ATRFullQuarterL = DayOpen - (ATR[1]) - (ATR[1]/4);
plot ATRFullHalfH = DayOpen + (ATR[1]) + (ATR[1]/2);
plot ATRFullHalfL = DayOpen - (ATR[1]) - (ATR[1]/2);
plot ATRFull3QuarterH = DayOpen + (ATR[1]) + (ATR[1]/2) + (ATR[1]/4);
plot ATRFull3QuarterL = DayOpen - (ATR[1]) - (ATR[1]/2) - (ATR[1]/4);
plot ATRFull2xH = DayOpen + (ATR[1]) + (ATR[1]);
plot ATRFull2xL = DayOpen - (ATR[1]) - (ATR[1]);


#LABEL
AddLabel(if showAtrLabel then 1 else 0, "ATR: " + Round(ATR,2) + " / Range: " + Round(Range,2) + " / " + Round(Range/ATR,2) +"xATR", Color.GRAY);



#CLOUDS
AddCloud(if !showClouds then NA else ATRFull2xH, ATRFull3QuarterH, CreateColor(160,160,160),CreateColor(160,160,160), no);
AddCloud(if !showClouds then NA else ATRFull3QuarterH, ATRFullHalfH, CreateColor(140,140,140),CreateColor(140,140,140), no);
AddCloud(if !showClouds then NA else ATRFullHalfH, ATRFullQuarterH, CreateColor(120,120,120),CreateColor(120,120,120), no);
AddCloud(if !showClouds then NA else ATRFullQuarterH, ATRFullH, CreateColor(100,100,100),CreateColor(100,100,100), no);
AddCloud(if !showClouds then NA else ATRFullH, ATR3QuarterH, CreateColor(80,80,80),CreateColor(80,80,80), no);
AddCloud(if !showClouds then NA else ATR3QuarterH, ATRHalfH, CreateColor(60,60,60),CreateColor(60,60,60), no);
AddCloud(if !showClouds then NA else ATRHalfH, ATRQuarterH, CreateColor(40,40,40),CreateColor(40,40,40), no);

AddCloud(if !showClouds then NA else ATRFull3QuarterL, ATRFull2xL, CreateColor(160,160,160),CreateColor(160,160,160), no);
AddCloud(if !showClouds then NA else ATRFullHalfL, ATRFull3QuarterL, CreateColor(140,140,140),CreateColor(140,140,140), no);
AddCloud(if !showClouds then NA else ATRFullQuarterL, ATRFullHalfL, CreateColor(120,120,120),CreateColor(120,120,120), no);
AddCloud(if !showClouds then NA else ATRFullL, ATRFullQuarterL, CreateColor(100,100,100),CreateColor(100,100,100), no);
AddCloud(if !showClouds then NA else ATR3QuarterL, ATRFullL, CreateColor(80,80,80),CreateColor(80,80,80), no);
AddCloud(if !showClouds then NA else ATRHalfL, ATR3QuarterL, CreateColor(60,60,60),CreateColor(60,60,60), no);
AddCloud(if !showClouds then NA else ATRQuarterL, ATRHalfL, CreateColor(40,40,40),CreateColor(40,40,40), no);

#FORMATTING
ATRQuarterH.Hide();
ATRQuarterL.Hide();
ATRHalfH.Hide();
ATRHalfL.Hide();
ATR3QuarterH.Hide();
ATR3QuarterL.Hide();
ATRFullH.Hide();
ATRFullL.Hide();
ATRFullQuarterH.Hide();
ATRFullQuarterL.Hide();
ATRFullHalfH.Hide();
ATRFullHalfL.Hide();
ATRFullHalfH.Hide();
ATRFullHalfL.Hide();
ATRFullHalfH.Hide();
ATRFullHalfL.Hide();
ATRFull3QuarterH.Hide();
ATRFull3QuarterL.Hide();
ATRFull2xH.Hide();
ATRFull2xL.Hide();

DayOpen.SetDefaultColor(Color.WHITE);
DayOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRQuarterH.SetDefaultColor(Color.GRAY);
ATRQuarterL.SetDefaultColor(Color.GRAY);
ATRQuarterH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRQuarterL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRHalfH.SetDefaultColor(Color.MAGENTA);
ATRHalfL.SetDefaultColor(Color.MAGENTA);
ATRHalfH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRHalfL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATR3QuarterH.SetDefaultColor(Color.GRAY);
ATR3QuarterL.SetDefaultColor(Color.GRAY);
ATR3QuarterH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATR3QuarterL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRFullH.SetDefaultColor(Color.MAGENTA);
ATRFullL.SetDefaultColor(Color.MAGENTA);
ATRFullH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRFullL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRFullQuarterH.SetDefaultColor(Color.GRAY);
ATRFullQuarterL.SetDefaultColor(Color.GRAY);
ATRFullQuarterH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRFullQuarterL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

ATRFullHalfH.SetDefaultColor(Color.MAGENTA);
ATRFullHalfL.SetDefaultColor(Color.MAGENTA);
ATRFullHalfH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ATRFullHalfL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hi welkin...this is great for /es that opens at 1800, gives you an ideal were it may go when markets open,but when you trade FB AAPL NVDA most stocks starts premarket at 4.00am, can you make the open at 4.00am? may give you a better ideal were some stocks will do during the day..thanks this is great script
 
hi welkin...this is great for /es that opens at 1800, gives you an ideal were it may go when markets open,but when you trade FB AAPL NVDA most stocks starts premarket at 4.00am, can you make the open at 4.00am? may give you a better ideal were some stocks will do during the day..thanks this is great script
Appreciate the feedback and glad you've found it useful in your trading. The open value is pulled from the daily aggregation, a new daily candle doesn't start until regular trading hours market open. It might be possible to do what you want, I have an idea of where to start, but I'll just have to dwell on it for a bit and figure it out how I'm going to script it. I feel that having the ATR levels plotted with the RTH market open as a base is key, so who knows how accurate the levels would be if it is plotted at premarket open. Been pretty busy lately, so can't really say when I'll get to mess around with it.
 
Last edited:
Appreciate the feedback and glad you've found it useful in your trading. The open value is pulled from the daily aggregation, a new daily candle doesn't start until regular trading hours market open. It might be possible to do what you want, I have an idea of where to start, but I'll just have to dwell on it for a bit and figure it out how I'm going to script it. I feel that having the ATR levels plotted with the RTH market open as a base is key, so who knows how accurate the levels would be if it is plotted at premarket open. Been pretty busy lately, so can't really say when I'll get to mess around with it.
thank you. appreciate you feed back
 
I wrote this yesterday. Just posting it in case someone finds it useful. Its a simple study that draws different color clouds between ATR levels. It plots from 1 ATR to 4.

Screenshot-102-edited.png


Code:
#WS TRADES

input price = close;
input displace = 0;
input length = 20;
input factor_Dn1 = -1.0;
input factor_Up1 = 1.0;
input factor_Dn2 = -2.0;
input factor_Up2 = 2.0;
input factor_Dn3 = -3.0;
input factor_Up3 = 3.0;
input factor_Dn4 = -4.0;
input factor_Up4 = 4.0;
input averageType = averageType.EXPONENTIAL;

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

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand1 = MidLine + factor_Dn1 * atr;
plot UpperBand1 = MidLine + factor_Up1 * atr;
plot LowerBand2 = midLine + factor_Dn2 * atr;
plot UpperBand2 = midline + factor_Up2 * atr;
plot LowerBand3 = midLine + factor_Dn3 * atr;
plot UpperBand3 = midLine + factor_Up3 * atr;
plot LowerBand4 = midLine + factor_Dn4 * atr;
plot UpperBand4 = midLine + factor_Up4 * atr;


AddCloud(UpperBand2, upperBand1, Color.ligHT_RED, Color.ligHT_RED);
AddCloud(LowerBand2, lowerband1, Color.ligHT_GREEN, Color.lighT_GREEN);
AddCloud(UpperBand3, upperBand2, Color.RED, Color.RED);
AddCloud(LowerBand3, lowerband2, Color.GREEN, Color.GREEN);
AddCloud(UpperBand4, upperBand3, Color.darK_RED, Color.darK_RED);
AddCloud(LowerBand4, lowerband3, Color.dARK_GREEN, Color.darK_GREEN);

Download link is http://tos.mx/0OilOjl
 
Last edited:
Nice setup! I have been using Keltner channels for ATR 1-3 from the median, and they seem to align slightly differently than your clouds. Do you also use Keltner channels or do you feel this is more accurate?
 
Nice setup! I have been using Keltner channels for ATR 1-3 from the median, and they seem to align slightly differently than your clouds. Do you also use Keltner channels or do you feel this is more accurate?
Its probably because I use the exponential moving average. I believe Keltner channels are Wilders moving average by default. You can change it in the settings if you like. I use exponential moving averages for all of my studies so I used it here as well just to keep it consistent. I wouldn't say its more accurate just my personal preference.
 
The author of the study isn't available on the forum to provide answers to questions. So this thread has been locked.
 
Last edited:
Status
Not open for further replies.

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