# How to calculate SMA values that are shown in chart IQ ? .

here are my steps.for calculating 20SMA in 10 minute time frame.
1. Last few days kite historical data for 10 minute interval at the current time
2. get last 20 OHLC VALUES
3. 20SMA = (close20 + close19 ...... + close3 +close2 + close1)/20
**close 1 will be the close price of the unformed candle at the current time.
Is this steps correct. i am getting different values from kite chart IQ . should i drop the last candle or not ? . i am finding SMA values for deploying a cross over strategy.
Tagged:
• it's very simple to calculate sma
how much variation do you get from chart IQ?
paste your code so others can help too
try numpy mean()
list = [ fetch historical data ]
20SMA = np.mean(list[-20:])
50SMA = np.mean(list[-50:])
that's it.
• edited November 8
import talib as ta
records =kite.historical_data(1208432, from_date=frm_date, to_date=to_date,interval='10minute')
df = pd.DataFrame(records)
close = df['close'].values
sma = ta.SMA(close,20)
• i get variation of upto 10 rs from chart iq for bank nifty .
• edited November 8
10rs is too much variation
I just now calculated it using talib and numpy and the calculations matches the IQ chart

Make sure that you have selected Moving average type as "SIMPLE" and not as "EXPONENTIAL" on your IQ charts
and right timeframe

try this

`token = 1208432fromDate = datetoDate = dateinterval = '10minute'df = pd.DataFrame(kite.historical_data(token, from_date=fromDate , to_date=toDate , interval=interval)df['SMA20'] = talib.SMA(df['close'], timeperiod=20)print(df)`