Repaints MTF Moving Average With Range Bands For ThinkOrSwim

Repaints

JamesRobertson

New member
Hello, I am not a coder and hoping to get some help here. I am wanting to get a cloud indicator (upper chart study) build with the following conditions.

1- I will be using this indicator on 5 min chart
2- The indicator should refer to 21 EMA on 30 minutes chart
3- Cloud should always run with the price candle and draw +70% and -70% range based on the 21 EMA on the 30 minutes chart.

Thank you
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Try this.
Inputs to change variables at Input Screen
Cloud colors can be changed at Globals at Input Screen
The range was adjusted from 70% to .7% at input for better fit.
The stair step vs smooth lines is how TOS displays higher timeframe aggregation lines on a lower aggregation chart

Screenshot-2022-12-24-094507.png
Ruby:
#ExpAvg_MTF_Cloud_Based_Upon_Range

input agg     = AggregationPeriod.THIRTY_MIN;
input range   = .7;
input length  = 21;
input avgtype = AverageType.EXPONENTIAL;

plot ema      = MovingAverage(avgtype, close(period = agg), length);
plot emah     = ema + (ema * range) / 100;
plot emal     = ema - (ema * range) / 100;

input showcloud = yes;
DefineGlobalColor("H", Color.LIGHT_RED);
DefineGlobalColor("L", Color.LIGHT_GREEN);
AddCloud(if showcloud then emah else Double.NaN, ema, GlobalColor("H"), GlobalColor("H"), showBorder = yes);
AddCloud(if showcloud then ema else Double.NaN, emal, GlobalColor("L"), GlobalColor("L"), showBorder = yes);
@JamesRobertson
 
Last edited by a moderator:
Try this.
Inputs to change variables at Input Screen
Cloud colors can be changed at Globals at Input Screen
The range was adjusted from 70% to .7% at input for better fit.
The stair step vs smooth lines is how TOS displays higher timeframe aggregation lines on a lower aggregation chart

Screenshot-2022-12-24-094507.png
Ruby:
#ExpAvg_MTF_Cloud_Based_Upon_Range

input agg     = AggregationPeriod.THIRTY_MIN;
input range   = .7;
input length  = 21;
input avgtype = AverageType.EXPONENTIAL;

plot ema      = MovingAverage(avgtype, close(period = agg), length);
plot emah     = ema + (ema * range) / 100;
plot emal     = ema - (ema * range) / 100;

input showcloud = yes;
DefineGlobalColor("H", Color.LIGHT_RED);
DefineGlobalColor("L", Color.LIGHT_GREEN);
AddCloud(if showcloud then emah else Double.NaN, ema, GlobalColor("H"), GlobalColor("H"), showBorder = yes);
AddCloud(if showcloud then ema else Double.NaN, emal, GlobalColor("L"), GlobalColor("L"), showBorder = yes);
@JamesRobertson
Thanks a ton. One slight change request please. I changed the cloud from RED and Green to Gray color but can't figure out the code that draws the upper, middle, and lower lines for the cloud. Can you please add settings to display/not display those lines on the cloud or remove the code that draws those lines? I got too many EMA lines already on the chart and these adds 3 more. I just want to see the cloud in Gray. Thank you
 
Thanks a ton. One slight change request please. I changed the cloud from RED and Green to Gray color but can't figure out the code that draws the upper, middle, and lower lines for the cloud. Can you please add settings to display/not display those lines on the cloud or remove the code that draws those lines? I got too many EMA lines already on the chart and these adds 3 more. I just want to see the cloud in Gray. Thank you

This should do those things

Screenshot-2022-12-24-133515.png
Ruby:
#ExpAvg_MTF_Cloud_Based_Upon_Range

input agg     = AggregationPeriod.THIRTY_MIN;
input range   = .7;
input length  = 21;
input avgtype = AverageType.EXPONENTIAL;
input hideplots = yes;

plot ema      = MovingAverage(avgtype, close(period = agg), length);
plot emah     = ema + (ema * range) / 100;
plot emal     = ema - (ema * range) / 100;

ema.SetHiding(hideplots);
emah.SetHiding(hideplots);
emal.SetHiding(hideplots);

input showcloud = yes;
DefineGlobalColor("H", Color.GRAY);
DefineGlobalColor("L", Color.GRAY);
AddCloud(if showcloud then emah else Double.NaN, ema, GlobalColor("H"), GlobalColor("H"));
AddCloud(if showcloud then ema else Double.NaN, emal, GlobalColor("L"), GlobalColor("L"));
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
330 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