ooples / OoplesFinance.StockIndicators

Largest C# stock indicator library with over 750 to choose from and easiest to use with abilities such as making an indicator out of any other indicator or using any moving average with any indicator.
Apache License 2.0
214 stars 55 forks source link

disclose sources #76

Open quiithub opened 3 months ago

quiithub commented 3 months ago

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 commented 3 months ago

@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

quiithub commented 3 months ago

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 commented 3 months ago

If you find any issues then please feel free to submit a pull request to fix them. This min or max was specifically done to fix a bug when using low values for the DC period

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: quiithub @.> Sent: Friday, August 2, 2024 6:03:05 PM To: ooples/OoplesFinance.StockIndicators @.> Cc: Franklin Moormann @.>; Mention @.> Subject: Re: [ooples/OoplesFinance.StockIndicators] disclose sources (Issue #76)

Thank you for the quick response @oopleshttps://github.com/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.

— Reply to this email directly, view it on GitHubhttps://github.com/ooples/OoplesFinance.StockIndicators/issues/76#issuecomment-2266196541, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAXO4ZJTPOTS4UTCFBT2E3TZPP6ZTAVCNFSM6AAAAABLOXCPZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRWGE4TMNJUGE. You are receiving this because you were mentioned.Message ID: @.***>

quiithub commented 3 months ago

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 commented 3 months ago

Yes that is what I meant as well. I found bugs with TV scripts and I'm local testing as well so I fixed them as I came across them

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: quiithub @.> Sent: Saturday, August 3, 2024 6:02:31 AM To: ooples/OoplesFinance.StockIndicators @.> Cc: Franklin Moormann @.>; Mention @.> Subject: Re: [ooples/OoplesFinance.StockIndicators] disclose sources (Issue #76)

Screenshot.2024-08-03.115755.png (view on web)https://github.com/user-attachments/assets/a015c7fb-beb2-4687-a3a4-8333e0cee8be 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.

— Reply to this email directly, view it on GitHubhttps://github.com/ooples/OoplesFinance.StockIndicators/issues/76#issuecomment-2266660518, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAXO4ZIZ3G7T2SO23X32A5TZPSTDPAVCNFSM6AAAAABLOXCPZGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRWGY3DANJRHA. You are receiving this because you were mentioned.Message ID: @.***>