How to Trade Simple Moving Averages - Python Automation Tutorial

Опубликовано: 15 Март 2026
на канале: Derrick Sherrill
50,611
1.4k

Learn How to trade stocks using simple moving averages and Python programming! #Python #AlphaVantage #Tutorial

Kite helps fund the channel, thanks for checking them out and supporting me --
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing. https://www.kite.com/get-kite/?utm_me...

The end result will be a Python script we can use to get real time simple moving averages and closing prices. Then we can take this data and create a plot that helps us identify trends and times to purchase and sell.

AlphaVantage API key request:
https://www.alphavantage.co/support/#...

More AlphaVantage Examples:
https://github.com/Derrick-Sherrill/a...

Install Pandas:
https://pandas.pydata.org/pandas-docs...

Install AlphaVantage:
https://alpha-vantage.readthedocs.io/...

Thanks so much for the continued support! 4500+ Subscribers at the time of writing! How awesome. The channel is really picking up and some really cool things are in the works. It wouldn't be possible without each of you. Thank so much for letting me make content and supporting me.

Join The Socials --
Picking Shoutouts Across YouTube, Insta, FB, and Twitter!
FB -   / codewithderrick  
Insta -   / codewithderrick  
Twitter -   / codewithderrick  
LinkedIn -   / derricksherrill  
GitHub - https://github.com/Derrick-Sherrill
*****************************************************************
Full code from the video:

import pandas as pd
from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.techindicators import TechIndicators
import matplotlib.pyplot as plt

api_key = 'RNZPXZ6Q9FEFMEHM'

ts = TimeSeries(key=api_key, output_format='pandas')
data_ts, meta_data_ts = ts.get_intraday(symbol='MSFT', interval='1min', outputsize='full')

period = 60

ti = TechIndicators(key=api_key, output_format='pandas')
data_ti, meta_data_ti = ti.get_sma(symbol='MSFT', interval='1min',
time_period=period, series_type='close')

df1 = data_ti
df2 = data_ts['4. close'].iloc[period-1::]

df2.index = df1.index

total_df = pd.concat([df1, df2], axis=1)
print(total_df)

total_df.plot()
plt.show()


Packages (& Versions) used in this video:
Pandas == 0.25.0
alpha_vantage
matplotlib

*****************************************************************
Code from this tutorial and all my others can be found on my GitHub:
https://github.com/Derrick-Sherrill/D...

Check out my website:
https://www.derricksherrill.com/

If you liked the video - please hit the like button. It means more than you know. Thanks for watching and thank you for all your support!!

Always looking for suggestions on what video to make next -- leave me a comment with your project! Happy Coding!