Force Index On Python

 

The force index (FI) is an indicator used in technical analysis to illustrate how strong the actual buying or selling pressure is. High positive values mean there is a strong rising trend, and low values signify a strong downward trend.


The FI is calculated by multiplying the difference between the last and previous closing prices by the volume of the commodity, yielding a momentum scaled by the volume. The strength of the force is determined by a larger price change or by a larger volume.


The Formula for the Force Index Is:

\begin{aligned} &\text{FI}\left(1\right)=\left(\text{CCP }-\text{ PCP}\right)*\text{VFI}\left(13\right)=\\ &\text{13-Period EMA of FI}\left(1\right)\\ &\textbf{where:}\\ &\text{FI = Force index}\\ &\text{CCP = Current close price}\\ &\text{PCP = Prior close price}\\ &\text{VFI = Volume force index}\\ &\text{EMA = Exponential moving average}\\ \end{aligned}

Now, here I'm using python to create a force index indicator.




#Technical indicator Force index
import pandas as pd
import pandas_datareader.data as web
import matplotlib.pyplot as plt


def ForceIndex(data,ndays):
    ForceIndex=pd.Series(data['Close'].diff(ndays)* data['Volume'],name='ForceIndex')
    data=data.join(ForceIndex)
    return data


data=web.DataReader('^NSEI',data_source='yahoo',start='1/1/2018', end='24/03/2021')
data=pd.DataFrame(data)


n=1
NSEI_ForceIndex = ForceIndex(data,n)
ForceIndex = NSEI_ForceIndex['ForceIndex']


fig=plt.figure(figsize=(11,9))
ax=fig.add_subplot(2,1,1)
ax.set_xticklabels([])
plt.plot(data['Close'],lw=1)
plt.title('NSEI Price Chart')
plt.ylabel('Close Price')
plt.grid(True)
bx=fig.add_subplot(2,1,2)
plt.plot(ForceIndex,'k',lw=0.75,linestyle='-',label='ForceIndex')
plt.legend(loc=2,prop={'size':9.5})
plt.ylabel('ForceIndex values')
plt.grid(True)
plt.setp(plt.gca().get_xticklabels(),rotation=30)
plt.show()




Comments

Popular posts from this blog

Net Present Value (NPV) On Python Using Numpy

Commodity Channel Index ( CCI ) Using Python

SMA Trading Strategy Using Python