The calculation of the Simple Moving Average is fairly simple. It has two properties - Length, Source like SMA(5, Close) takes the closing prices of the last 5 points and divides it by 5.
It is regardless of the timeframe. If you take the points on an hourly timeframe i.e. you feed the data one closing point at the end of each hour. SMA(5, Close) will take the closing prices of the last 5 points and divides it by 5.
Here is SMA(5,Close) and SMA(10,Close) plotted into INFY.
Use the function “Make it mine” to play around with the chart in Tradingview.
As per the Moving Average Crossover Strategy’s theory, when SMA of smaller length crosses the SMA of bigger length, it will generate a buy signal.
Also, the source has to be (here, it is assumed “close”) the same.
Let’s get down to the coding and see the difficulties we face. We shall be using Alice Blue and API credentials of my dummy account. (Unless someone changes the password, it will work fine enough for everyone’s testing.)
We shall use Python.
Using Jupyter Notebooks, You can easily use Python without even installing Python in your laptop.
I’m assuming everyone has a Google account. We will use Google Collab which will allow us to test this without a further headache.
Let’s install the Python SDK for Alice Blue API written by @Krishna Velu; otherwise, it would be a nightmare.
pip install alice-blue and press enter.