• Get $40 off VIP by signing up for a free account! Sign Up

Previous Day Close Moving Averages

ziongotoptions

Active member
Hello can anyone code a script that plots horizontal lines of the previous day closing moving averages for the 5-day EMA, 10-day EMA, 21-day EMA, 50-day SMA, 100-Day SMA and 200-Day SMA that shows at the beginning of the premarket session? I would really appreciate it
 
TOS has a built in study called DailySMA you can apply to a chart multiple times to handle all of your simple averages. Copy their code for that one to a new study and change Average to ExpAverage on line 16 to create the same thing for exponential averages.
 

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

TOS has a built in study called DailySMA you can apply to a chart multiple times to handle all of your simple averages. Copy their code for that one to a new study and change Average to ExpAverage on line 16 to create the same thing for exponential averages.
Thank You, I was able to find this code, do you know how to modify the code so that the lines from the previous day are connected together?
Ruby:
plot ema5 = expAverage(close(period = aggregationPeriod.DAY)[1],5) ;

plot ema10 = expAverage(close(period = AggregationPeriod.DAY)[1],10);

plot ema21 = expaverage(close(period = AggregationPeriod.DAY)[1],21);

plot sma50 = average(close(period = AggregationPeriod.DAY)[1],50);

plot sma100 = average(close(period = AggregationPeriod.DAY)[1],100);

plot sma200 = average(close(period = AggregationPeriod.DAY)[1],200);



ema5.setPaintingStrategy(paintingStrategy.HORIZONTAL);

ema10.setpaintingStrategy(paintingStrategy.HORIZONTAL);

ema21.setpaintingStrategy(paintingStrategy.HORIZONTAL);

sma50.setpaintingStrategy(paintingStrategy.HORIZONTAL);

sma100.setpaintingStrategy(paintingStrategy.HORIZONTAL);

sma200.setPaintingStrategy(paintingStrategy.HORIZONTAL);
 
Thank You, I was able to find this code, do you know how to modify the code so that the lines from the previous day are connected together?

Yes, that code should do what you want. To have no break in the lines between days, remove all of that stuff at the bottom that sets the painting strategy to horizontal.

A downside of having all of this in one study is none of the plots will show on new stocks that don't have 200 days of data yet. That's why I recommended using the the built in study and adding it to the chart for each average length. That way the exponentials always show and each simple shows as soon as it has enough data for its length. The exponentials could be all in one study without having this same problem but not the simples.
 
Yes, that code should do what you want. To have no break in the lines between days, remove all of that stuff at the bottom that sets the painting strategy to horizontal.

A downside of having all of this in one study is none of the plots will show on new stocks that don't have 200 days of data yet. That's why I recommended using the the built in study and adding it to the chart for each average length. That way the exponentials always show and each simple shows as soon as it has enough data for its length. The exponentials could be all in one study without having this same problem but not the simples.
thank you for all your knowledge, i don't plan to day trade penny stocks mostly mid-cap and bluechip stocks, but ill keep that in mind if I do
 
thank you for all your knowledge, i don't plan to day trade penny stocks mostly mid-cap and bluechip stocks, but ill keep that in mind if I do

You're obviously welcome to do whatever you feel is appropriate for your trading.

For others who may read this thread:
It has nothing to do with the price of the stock. It's based on how long the stock has existed, which has nothing to do with market cap or even how long the company has existed. When large companies merge they often form a new legal entity with a new, though still recognizable, name and trade under a new ticker. There's 220 trading days in a year. With the code above the lines will not show until 200 trading days have passed. Same for any IPO. You may or may not want to trade it in its early days but it'll be almost a year later when your lines finally show up.
 
Thank You, I was able to find this code, do you know how to modify the code so that the lines from the previous day are connected together?
Ruby:
plot ema5 = expAverage(close(period = aggregationPeriod.DAY)[1],5) ;

plot ema10 = expAverage(close(period = AggregationPeriod.DAY)[1],10);

plot ema21 = expaverage(close(period = AggregationPeriod.DAY)[1],21);

plot sma50 = average(close(period = AggregationPeriod.DAY)[1],50);

plot sma100 = average(close(period = AggregationPeriod.DAY)[1],100);

plot sma200 = average(close(period = AggregationPeriod.DAY)[1],200);



ema5.setPaintingStrategy(paintingStrategy.HORIZONTAL);

ema10.setpaintingStrategy(paintingStrategy.HORIZONTAL);

ema21.setpaintingStrategy(paintingStrategy.HORIZONTAL);

sma50.setpaintingStrategy(paintingStrategy.HORIZONTAL);

sma100.setpaintingStrategy(paintingStrategy.HORIZONTAL);

sma200.setPaintingStrategy(paintingStrategy.HORIZONTAL);
@Slippage
Is it possible to change the aggregation period? I tried changing to lower periods but it does not plot. Thank you
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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