Simple Moving Average is one of the Techncial Indicator widely used with other technical indicators which i already explained in this post SMA.
Exactly in this one i'm extracting the price of NIFTY 50 from KiteConnect then trying to Build Simple Moving Average with the help of Pandas Dataframes and then try to Plot with the help of Matplotlib.
So let's get started,all you need in this is to set access token and api key for that you need to follow this you tube video Automate Trade-KiteConnect-Python API Trading Platform-StockMarket-Part 1 after that need to define the Simple Moving Average to Compute it and then need to set instument token which you can get from by just pasting this URL https://api.kite.trade/instruments in your browser and after that a download will start just save the file as filename.csv then find out the instrument_token which you need to extract the minute data for it's analysis then exactly set from and to date and set the interval as per your wish for minute data you ask for as minute,5minute,10minute,15minute,30minute and 60minute you can set interval day also to fetch datas of previous day and exactly need to define which date you want in particular.
From date and to date should be in the format of yyyy-mm-dd then after call the data in a dataframe and then enjoy you built an SMA with the help of KiteConnect data.
This Post i Just Created so you actually can visualize the data with the help of KiteConnect for Further Please follow the Video for Proper Instructions then Code Input.
#import the Necessary Package module
from kiteconnect import KiteConnect
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import style
api_key= 'your_api_key'
api_secret='your_api_secret'
kite = KiteConnect(api_key=api_key)
'''
If you need access token from idle just comment out the below 2 line then afte place the access token to the 3rd line
####KRT=kite.request_access_token('your_request_token',api_secret)
####print(KRT)
kite.set_access_token('your_access_token')
style.use('fivethirtyeight')
def MA(data,n):
MA=pd.Series(pd.rolling_mean(data['close'],n),name='MA')
data=data.join(MA)
return data
data=kite.historical(instrument_token='256265',from_date='2017-08-21',to_date='2017-08-21',interval='minute')
data=pd.DataFrame(data)
n=2
SMA=MA(data,n)
MA=SMA['MA']
print(SMA)
SMA.plot()
plt.show()
--End of Code Input--
Have any Doubt regarding this please do Comment and Please do Share us On Various Social Media PLatform: