Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Help with Arrays not DataSeries Compiles won't run
I'm working on some code from John Ehler's. In his notes he says of the code,
"First the entire code is completed for each bar and the values of the variables are retained from bar to bar. However, the values of the arrays are not automatically indexed to each price bar."
So I used arrays instead of DataSeries.... At first I declared and initalized in one step in the variables section. They are all the same size and all hold a double value.
double[] q = new double[50];
That compiles but on bar six, at the first line, and first time I try to address the first array by looping through it and storing some computed values, the script fails and I get the error message in the log, Error on calling 'OnBarUpdate' method for indicator CycleSpectrum on bar 6: Index was outside the bounds of the array.
The first index I tried to access is q[8] to assign a value to it inside a loop.
So I tried splitting up the declaration in the variables section:
double[] q;
and then under protected override void Initialize()
q = new double[50];
but that didn't help... I still get the "Index was outside the bounds of the array." error message in the log.
Any help greatly appreciated.
Relevant snippets:
In Variables region:
private int n = 0;
double[] q;
In protected override void Initialize() method:
q = new double[50];
Probably a math error, division by zero, reference to an index that doesn't exist, this kinda stuff. Hard to troubleshoot code snippets, plus I don't use NT. Hopefully someone else can help.