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

Several Divide by zero exceptions #56

Closed
pahlot opened this issue Jul 17, 2018 · 6 comments
Closed

Several Divide by zero exceptions #56

pahlot opened this issue Jul 17, 2018 · 6 comments

Comments

@pahlot
Copy link
Contributor

pahlot commented Jul 17, 2018

Hi,

Working against 3.1;

after much digging I have found that if a price hasn't moved within a given period of time the CCI will cause a DivideByZero exception @ line 29 because the mean deviation is 0.

To reproduce:
`[TestMethod]
public void Expect_CCI_Exception()
{
var candles = new List();
for(int i = 0; i <= 100; i++)
{
candles.Add(new Candle()
{
Open = 0.03m,
Close = 0.03m
});
}
Assert.ThrowsException(() => candles.Cci(20));

    }`
@pahlot
Copy link
Contributor Author

pahlot commented Jul 17, 2018

Same with the ADX. Still tracing the source of that one...

[TestMethod] public void Expect_ADX_Exception() { var candles = new List<Candle>(); for (int i = 0; i <= 100; i++) { candles.Add(new Candle() { Open = 0.03m, Close = 0.03m }); } Assert.ThrowsException<DivideByZeroException>(() => candles.Adx(20)); }

@pahlot
Copy link
Contributor Author

pahlot commented Jul 17, 2018

And DMI

[TestMethod] public void Expect_DMI_Exception() { var candles = new List<Candle>(); for (int i = 0; i <= 100; i++) { candles.Add(new Candle() { Open = 0.03m, Close = 0.03m }); } Assert.ThrowsException<DivideByZeroException>(() => candles.Dmi(20)); }

@pahlot pahlot changed the title CCI Divide by zero exception Several Divide by zero exception Jul 17, 2018
@pahlot pahlot changed the title Several Divide by zero exception Several Divide by zero exceptions Jul 17, 2018
@pahlot
Copy link
Contributor Author

pahlot commented Jul 17, 2018

I dare say there may be others, but I am running out of time as I am about to go away for work.

Could refactor any divisions to something like;

static public decimal SafeDivision(this decimal numerator, decimal denominator) { (numerator == 0) ?? return 0; return (denominator == 0) ? 0 : numerator / denominator; }

@karlwancl
Copy link
Owner

@pahlot thanks for pointing out. I need some time to check all the indicator for the division.

@pahlot
Copy link
Contributor Author

pahlot commented Jul 17, 2018

@lppkarl that's understandable. I was thinking about how to best test this along with expending on how we can use the indicators.

I haven't got the time in the next few weeks but what I was thinking is to have a mechanism of discovery of and registration of indicators.

something (very roughly like);

IDiscoverableIndcator { string Key => $"nameOf(theIndecator)_{ConfigValue}"; string FriendlyName; int DefaultConfigValue = 20; int ConfigValue = 20; }

And then a discovery service to list each. This will allow us to have a common discoverable interface for custom implementations, and also register an indicator with a custom config value.

So we could have something like;

indicator.GetByName(name);
indicator.GetInstancesOf();

etc

This would then also allow us to run any new indicators against a common test, such as making sure there is no DivideByZero issue in one foul swoop.

Just an idea.

@karlwancl
Copy link
Owner

@pahlot Thanks for the idea, but i just want to make something clear. Do you mean we introduce an IDiscoverableIndicator, and make all Analyzables (the base of all indicators) implement this, and we create a test case to discover all these indicators and test the case? I am a bit confuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants