Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disclose sources #76

Open
quiithub opened this issue Jul 25, 2024 · 7 comments
Open

disclose sources #76

quiithub opened this issue Jul 25, 2024 · 7 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Comments

@quiithub
Copy link
Contributor

Hi ooples,
thank you for sharing such a big collection of indicators.
Can you please disclose your sources of them?
For me it is often not clear on which source the indicators are based on, when trying to verify the calculations.
But this is my opinion crucial to build trust in the calculation.
For instance in "RecursiveRelativeStrengthIndex" I found this loop:

            for (var j = 1; j <= length; j++)
            {
                var prevB = i >= j ? bList[i - j] : src;
                var prevAvg = i >= j ? avgList[i - j] : 0;
                var prevGain = i >= j ? gainList[i - j] : 0;
                var prevLoss = i >= j ? lossList[i - j] : 0;
                var k = (double)j / length;
                var a = rsi * ((double)length / j);
                avg = (a + prevB) / 2;
                var avgChg = avg - prevAvg;
                gain = avgChg > 0 ? avgChg : 0;
                loss = avgChg < 0 ? Math.Abs(avgChg) : 0;
                var avgGain = (gain * k) + (prevGain * (1 - k));
                var avgLoss = (loss * k) + (prevLoss * (1 - k));
                var rs = avgLoss != 0 ? avgGain / avgLoss : 0;
                avgRsi = avgLoss == 0 ? 100 : avgGain == 0 ? 0 : MinOrMax(100 - (100 / (1 + rs)), 1, 0);
                b = avgRsiList.Count >= length ? avgRsiList.TakeLastExt(length).Average() : avgRsi;
            }
            bList.AddRounded(b);
            avgList.AddRounded(avg);
            gainList.AddRounded(gain);
            lossList.AddRounded(loss);
            avgRsiList.AddRounded(avgRsi);

It appears that only the last iteration of the loop is considered for the calculation b, avg, gain, loss, avgRsi because there is only the single equal operator inside the loop over j. I guess the operator must be something like ´+=´.

I hope this message reaches you well.

Best regards

@ooples
Copy link
Owner

ooples commented Jul 26, 2024

@quiithub You make very good points and I did create a full page for all indicators in the library along with a link to each source that you can view here: https://ooples.github.io/OoplesFinance.StockIndicators/indicators

I clearly haven't done a good enough job advertising this link but you can find the original source code I converted to C# and if you spot any mistakes I made with any of my code, please feel free to create a pull request. It is very difficult for me to keep up with almost 800 indicators by myself

@ooples ooples added help wanted Extra attention is needed good first issue Good for newcomers question Further information is requested labels Jul 26, 2024
@quiithub
Copy link
Contributor Author

quiithub commented Aug 2, 2024

Thank you for the quick response @ooples
And I am glad you already made the effort to list the sources.
However for "your" indicators (where you are the source) which one is the master?
The c# library or the one on tradingview?
For example https://www.tradingview.com/script/z46ko6yt-Ehlers-Sinewave-Indicator-V2-CC/ adds up without limiting min and max:

    real += math.sin(2 * pi * i / dcPeriod) * nz(cycle[i])
    imag += math.cos(2 * pi * i / dcPeriod) * nz(cycle[i])

and your c# implementation using MinOrMax

                realPart += Math.Sin(MinOrMax(2 * Math.PI * ((double)j / dcPeriod), 0.99, 0.01)) * prevCycle;
                imagPart += Math.Cos(MinOrMax(2 * Math.PI * ((double)j / dcPeriod), 0.99, 0.01)) * prevCycle;

causing different results (for me at least as I tried to translate to python.

@ooples
Copy link
Owner

ooples commented Aug 2, 2024 via email

@quiithub
Copy link
Contributor Author

quiithub commented Aug 3, 2024

Screenshot 2024-08-03 115755
Is it possible that these bugs are also in the tradingview scripts?
I plotted the imagPart of EhlersSpectrumDerivedFilterBank in tradingview and periodically I get extreme values.

@ooples
Copy link
Owner

ooples commented Aug 3, 2024 via email

@quiithub
Copy link
Contributor Author

Hi Franklin, on tradingview the internal bar strength is basically computed as follows:

ibsi = ema(sma(ibs, smoothLength), length)
ibsiEma = ema(ibsi, length)

but in this package:

ibsi = sma(ibs, smoothLength)
ibsiEma = ema(ibsi, length)

Which version is right?
Is the idea for the indicator from you?

@ooples
Copy link
Owner

ooples commented Nov 28, 2024

@quiithub I'm the one who created that TV indicator script and that second smoothed EMA is the signal line. I kept the version here a bit different since I wasn't super happy with my TV script but feel free to create a PR to make this change if you want. I can also make this change to add additional smoothing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants