Resetting intraday MAs

banya

New member
Hello all, I am new here!

I want to develop a moving average for a $TICK chart. As $TICK starts fresh upon market open, the intraday moving average also has to start fresh with market open.

Any help will be greatly appreciated.
Thanks in advance.
 
Last edited:
There is a setting for each instrument type in Chart Settings where you check the checkbox to start aggregation at market open, as well as other settings like whether to show after hours and premarket data...
 
I was not very clear about what I want. "Resetting" meant calculating moving averages with completely new data for new day, excluding previous days history data. This is for $TICK chart.
 
@banya,

You can display a moving average of any set of data points you choose. If you build yourself a time series in this way:
Code:
def series = if SecondsFromTime(0930) >= 0 then CLOSE else Double.NaN;
you effectively tell ToS that if the data point is before the opening bell (or whatever time you choose) then please ignore it and put a NaN (Not A Number or NULL) into my series.
Next you then take a moving average based on that series thusly:
Code:
plot MovAvg = MovingAverage(AverageType.SIMPLE, series, 12);
you will have a simple moving average over 12 bars that starts, quite literally, from nothing at 9:30 AM.

N.B. This will not plot anything for the first 12 bars of the day. I'm not sure that's an intended consequence of your request, but moving averages can't start until they have a full length of data points to work with. I'm sure there are forumlae out there that can construct a pseudo-moving average over the interim bars, but this snippet does not.

Nihil ante tempus q.e.d.
;-)

-mashume
 
A great help - I've been looking for this for a while. Here's what worked for me with $ADD

Code:
# JS_TwoMovingAverages_ResetEachDay
# based on MovAvgTwoLines
#

#use this code to reset the moving averages to start afresh with each day
def price = if SecondsTillTime(930) < 0 and SecondsTillTime(1600) > 0 then close else Double.NAN;
input fastLength = 9;
input slowLength = 18;
input displace = 0;
input averageType = AverageType.SIMPLE;

plot fastAvg = MovingAverage(averageType, price[-displace], fastLength);
plot slowAvg = MovingAverage(averageType, price[-displace], slowLength);

fastAvg.SetDefaultColor(GetColor(1));
slowAvg.SetDefaultColor(GetColor(0));
 

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