I have been trying along to implement the Chande Forecast Oscillator Algorithm with hourly candle stick data from NSE in python. I am using ChartIq charts to verify my results of the indicator results manually. But the results of my implementation of this algorithm is not matching with the output shown below.
I have implemented the algorithm mentioned in this link.
chande forecast oscillator formula, which is basicaly:
1. input N represents the period (sample of data points to take to calculate linear regression)
2. let reg be the coeffients of the regression model which uses ordinary least squares to find out the coefficients.
3. predict the
result[i] = ((close[i] - y_pred[i]) * 100) / close[i]
But this is not matching with the chart iq data of indicators which gets displayed in zerodha kite.
My Algorithm in Python
My algorithm plot
Black line indicates the linear regression line.
Blue scatter plot is the closing price of each candle over the last 861 hours.
Red line is the CFO algorithm output for all 861 points with period=14
Actual Zerodha/ChartIq representation
tail output from the results column does not seem to matching chartiq result
From my understanding as it is a time series data hence I am considering:
X: [i for i in range(offset,offset + period)]
Y: [close_price[i] for i in range(offset,offset + period)]
I am stuck and I really need help. Please tell me what am I doing wrong or if you can help me understand what is the mistake is calculating the linear regression ?
I have even tried the SMA and EMA approaches of this algorithm as well mentioned in the following link
cTrader algorithm of CFO
Need a bit of help here as I am totally new to algorithmic trading and have no clue of this indicator.