Change
for(int i=1;i<=limit; i++) // // for(int j=1;j<=limit;j++)
to
for(int i=1;i<limit; i++) // // for(int j=1;j<limit;j++)
On first run, prev_calculated==0, so limit==Bars.
You are trying to access an array element that doesn't exist and getting an array out of range error.
Because you count up in the loop, the buy buffer is being filled before the error occurs.
Thanks, GumRai.
It works now!
Yes, on first run, limit==Bars.
So it will run from i=1 to N (count up in the loop). I am not clear why a given element of the array (1-N) doesn't exist.
Can you explain it please?
SCFX
You can figure it out youself if you can answer these questions.
Assume 100 bars, the lowest bar index is zero.
What is the highest bar index ?
What is the value of Bars ?
Is the highest bar index the same as the value of Bars ?
Oh,
Great way to teach, SDC.
so it ranges from 0-99. value bar=100.
limit<=100 --> bar 100 is not there yet.
I got it.
But you know, the i<=limit has not caused me any trouble before :(
Have a nice weekend.
SCFX
GumRai: Change
for(int i=1;i<=limit; i++) to for(int i=1;i<limit; i++) | Will NOT work. You do NOT loop from 0 (or 1) to rates_total-prev_calculated You loop from notDone to rates_total-1. rates_total-1 is the newest forming bar and 0 is the oldest bar. |
WHRoeder:
Will NOT work. You do NOT loop from 0 (or 1) to rates_total-prev_calculated You loop from notDone to rates_total-1. rates_total-1 is the newest forming bar and 0 is the oldest bar.
That is only the case if you reverse the buffers and series arrays.
These are the main considerations when creating indicator loops,
- rates_total == total number of bars
- prev_calculated == 0 on initial load or when chart history is added
- prev_calculated == rates-total-1 the rest of the time
- buffer indexing direction
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi Everyone,
I cannot understand why the following structure doesn't work.
When I attach to chart, ONLY buffer buy has value.
To my understand, it will run the 2 sequences one by one. So the first FOR() will be fully run first --> I have buy buffer. Then the second FOR() will be processed.
(it is for illustration of the problem, so it seems silly not using if else)
Thank you for your help.
SCFX