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

CalculateNegativeVolumeIndex, CalculatePositiveVolumeIndex alwas return array of zeros #40

Open
siesta-trading opened this issue Jul 25, 2023 · 4 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@siesta-trading
Copy link

double nvi = currentVolume >= prevVolume ? prevNvi : prevNvi + (prevNvi * pctChg);

The problem is here:

double prevNvi = nviList.LastOrDefault();
double nvi = currentVolume >= prevVolume ? prevNvi : prevNvi + (prevNvi * pctChg);
nviList.AddRounded(nvi);

because prevNvi is initialized as 0 and therefore nvi also assigned 0 and on next iteration prevNvi again assigned 0 and so on.
solution: prevNvi should never be assigned 0.

ooples added a commit that referenced this issue Aug 2, 2023
…#40

Changed many variables to use var keyword instead
@ooples
Copy link
Owner

ooples commented Aug 2, 2023

@siesta-trading I just did a commit that fixes this issue in both calculations so can you please get the latest version and test it to make sure it is working now?

@siesta-trading
Copy link
Author

I was looking at the fix you have implemented.
I think there is still a possibility that nvi can be set to 0 and therefore the problem persists.
For example:

Iteration 1:
i=0
prevNvi=1000
nvi=1000

iteration 2:
i=1
prevNvi=1000
pctChg=-1
currentVolume < prevVolume
nvi=0(!!!)

back to the original issue.
I would recommend the solution to be something like:
if (prevNvi == 0)
prevNvi=0.0001;

@ooples
Copy link
Owner

ooples commented Aug 8, 2023

@siesta-trading I fixed the issue you found and moved the initial value to the parameter so you can override with your own custom value as well

@ooples ooples self-assigned this Oct 21, 2023
@ooples ooples added bug Something isn't working question Further information is requested labels Oct 21, 2023
@ooples
Copy link
Owner

ooples commented Oct 21, 2023

@siesta-trading Please confirm that your issue was fixed with the most recent version and close this issue if it is resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants