peerchemist / finta

Common financial technical indicators implemented in Pandas.
GNU Lesser General Public License v3.0
2.13k stars 694 forks source link

CCI output not matching with Tv results ;OBV result too not matching with tradingview #29

Closed mbmarx closed 5 years ago

mbmarx commented 5 years ago

Tested this TA.CCI(df) output comparing with tradingview.com(TV) chart inbuilt CCI ,the output is not matching .

In finta.py did a small change and the output CCI is almost closest to tradingview output but not sure how this is very close to the result shown in TV.

Modified Code:def CCI(cls... part tp = cls.TP(ohlc) return pd.Series( (tp - tp.rolling(window=period,center=False).mean()) / (0.015 * tp.rolling(window=period,center=False).std()), name="{0} period CCI".format(period), )

Here is the calculation method ,TV is the standard worldwide proven indicator methods ,it would be good if we see your indicator output same as TV result. I have checked many source yours is very closest.Run the above code you will get only 20points differrence in the result.

In summary if we calculate the "Mean Deviation" correctly the output will be matching with global standards.

There are several steps involved in calculating the Commodity Channel Index. The following example is for a typical 20 Period CCI:

CCI = (Typical Price - 20 Period SMA of TP) / (.015 x Mean Deviation)

Typical Price (TP) = (High + Low + Close)/3

Constant = .015 The Constant is set at .015 for scaling purposes. By including the constant, the majority of CCI values will fall within the 100 to -100 range.

There are three steps to calculating the Mean Deviation.

  1. Subtract the most recent 20 Period Simple Moving from each typical price (TP) for the Period.
  2. Sum these numbers strictly using absolute values.
  3. Divide the value generated in step 3 by the total number of Periods (20 in this case).
peerchemist commented 5 years ago

Here is the calculation method ,TV is the standard worldwide proven indicator methods ,it would be good if we see your indicator output same as TV result. I have checked many source yours is very closest.

Please mind that TV runs the number in the browser, in javascript. There is a lot of rounding to increase the performance and responsiveness. Finta runs on numpy, which is made in fortran, a language commonly used for mathematics and physics.

If equation is set correctly, Finta will yield more accurate results than TV. This is why numbers may end up close to what is shown on TV, but not exactly the same.

mbmarx commented 5 years ago

Dear PeerChemist, The formula used for CCI is entirely different in TV than the one given here. Is there a chance you can adapt TV CCI accurately here. Since none of the github produces the same result as TV it will be of great help. only CCI and OBV not matching the result with TV ,MFI i verified it is exactly matching . i feel bit of change in the logic would yield the correct result and this will help to make correct strategy.

mbmarx commented 5 years ago

The tradingview formula i got from support team is this one

//@version=3 study(title="Commodity Channel Index", shorttitle="CCI") length = input(20, minval=1) src = input(close, title="Source") ma = sma(src, length) cci = (src - ma) / (0.015 * dev(src, length)) plot(cci, color=olive) band1 = hline(100, color=gray, linestyle=dashed) band0 = hline(-100, color=gray, linestyle=dashed) fill(band1, band0, color=olive)

//@version=3 study(title="On Balance Volume", shorttitle="OBV") src = close obv = cum(change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume) plot(obv, color=blue, title="OBV")

peerchemist commented 5 years ago

Okay I'll see what I can do.

peerchemist commented 5 years ago

Please checkout latest master branch and test again.

mbmarx commented 5 years ago

With respect to CCI i do not see any change in the master branch. On the OBV also it is not matching with tv output .any idea in near feature you will update this too.

Please make the OBV is exactly giving output of tradingview ;None of the todays available indicator matching this OBV

peerchemist commented 5 years ago

Have you considered that TV is wrong?

mbmarx commented 5 years ago

TV could be wrong ,the feedback on the calculation that they are using is this one . Though it might be wrong ,getting the same output is important to make my strategy testing to take off. This is the response i got from them ; //@version=3 study(title="Commodity Channel Index", shorttitle="CCI") length = input(20, minval=1) src = input(close, title="Source") ma = sma(src, length) cci = (src - ma) / (0.015 * dev(src, length)) plot(cci, color=olive) band1 = hline(100, color=gray, linestyle=dashed) band0 = hline(-100, color=gray, linestyle=dashed) fill(band1, band0, color=olive)

//@version=3 study(title="On Balance Volume", shorttitle="OBV") src = close obv = cum(change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume) plot(obv, color=blue, title="OBV")

TV CCI uses only close as input no hlc/3 value used .so i made a minor change in the code to get the exact cci output it is working.

OBV is something still not working ,yet to test with latest commit code ;is the latest commit in master branch.

On Sat, Jun 1, 2019 at 7:03 PM peerchemist notifications@github.com wrote:

Have you considered that TV is wrong?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/peerchemist/finta/issues/29?email_source=notifications&email_token=AIC5A5LZGFOTBSUFE4WNZHLPYJ3DNA5CNFSM4HQOXM62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWXAYJI#issuecomment-497945637, or mute the thread https://github.com/notifications/unsubscribe-auth/AIC5A5KN4JUMBISPZUE4HSTPYJ3DNANCNFSM4HQOXM6Q .

-- Regards, Marx Chidambara Babu M.B

mbmarx commented 5 years ago

Hi PeerChemist, I think the OBV is not matching as the way it is calculated by TV is different than what is used by all. Can you please check this code and references for getting the same outputs.

//@version=3 study(title="On Balance Volume", shorttitle="OBV") src = close obv = cum(change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume) plot(obv, color=blue, title="OBV")

And the Feedback from TV;If we take care of the Cum calculation it might match. Can you at least provide the code to do testing with this mentioned changes by Tv team.

You can find the info about dev here: https://getsatisfaction.com/tradingview/topics/how-does-dev-function-work#reply%3Ci%3E19824422 cum(x) is a sum of all values of x on the current and all previous bars. It is calculated on the whole barset http://mathworld.wolfram.com/CumulativeSum.html.

mbmarx commented 5 years ago

Now the issue with the latest update is resolved. the output is matching with TV for CCI ,MFI and OBV.

mbmarx commented 5 years ago

Hey,

I just signed the petition "Prime Minister of India : Ban Glyphosate and its mixtures including RoundUp! @PMOIndia @icarindia ‏@moefcc ‏" and wanted to see if you could help by adding your name.

Our goal is to reach 75,000 signatures and we need more support. You can read more and sign the petition here:

http://chng.it/R2rnK8HBDD

Thanks! Marx