Simple Moving Average Using STOCKHISTORY

Data123

Board Regular
Joined
Feb 15, 2024
Messages
68
Office Version
  1. 365
Platform
  1. Windows
Hi is there a way to create a simple moving average (20 days) for stocks using stockhistory, workday and today in the formula? Thanks!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
See if this works for you.
I used the starting date in the STOCKHISTORY as TODAY - 40 days. This gets the last 20 days plus sum extra days of closing prices.
I then used the TAKE function to get the most current 20 days and then took the AVERAGE.

Book1
AB
1StockAverage last 20 days
2MSFT409.58
Sheet2
Cell Formulas
RangeFormula
B2B2=AVERAGE(TAKE(STOCKHISTORY(A2,TODAY()-40,TODAY(),0,,1),-20))
 
Upvote 0
Solution
Didn't know about this function. This is very helpful. Thanks for asking it!
 
Upvote 0
See if this works for you.
I used the starting date in the STOCKHISTORY as TODAY - 40 days. This gets the last 20 days plus sum extra days of closing prices.
I then used the TAKE function to get the most current 20 days and then took the AVERAGE.

Book1
AB
1StockAverage last 20 days
2MSFT409.58
Sheet2
Cell Formulas
RangeFormula
B2B2=AVERAGE(TAKE(STOCKHISTORY(A2,TODAY()-40,TODAY(),0,,1),-20))
Thanks AhoyNC, that should work!
 
Upvote 0
You're welcome. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top