Code A Simple Moving Average Stock Trading Strategy

randerson112358
4 min readSep 25, 2021

A Simple Moving Average Trading Strategy Using Python

Disclaimer: The material in this article is purely educational and should not be taken as professional investment advice. Invest at your own discretion.

In this article, I will talk about how I implemented a simple trading strategy to determine when to buy and sell an asset using the python programming language. This strategy will use the Simple Moving Average indicator.

What Is A Simple Moving Average (SMA)?

According to Investopedia, a simple moving average (SMA) calculates the average of a selected range of prices, usually closing prices, by the number of periods in that range.

The Strategy

If the price of the asset moves above the Simple Moving Average (SMA) then sell. If the price moves below the Simple Moving Average (SMA) then buy and of course never sell at a price lower than you bought.

The Strategy:
1.Buy when the SMA30 goes below the close price
2.Sell when the SMA30 goes above the close price
3.Never sell at a price lower than you bought

--

--