problem with Arrays in MLQ4

 

Why wont MLQ4 let me do this:

escape[index] = Bid;

When I check escape[index] or escape[0] it is empty (0).

MLQ4 will let me do the following however:

escape[0] = Bid;

OR escape[1] = Bid;

In both these cases it works: the value of Bid gets assigned to the array.

I just dont understand why MLQ4 wont allow me to do this. I have cut and paste the crucial/relevant/salient elements of the code below.


------------------------------

double escape[100000];
int index;

int start() // Special function start()
{

escape[index] = Bid;
index++;


-------------------------------

To my mind what should happen with above code is that the "escape" array should just get filled up from escape[0] to escape[100000] with Bid values. BUT this does not happen. And i cant figure out why not. If someone can point out where Im going wrong will be very grateful.

xxx

 

Looks ok to me. Try again.

 

Is the index or the array zeroed for each tick?

try turning the index and the array into static variables.

 

  1. double escape[100000];
    int index;
    
    int start() // Special function start()
    {
       escape[index] = Bid;
       index++;
    This should work until index reaches 100K at which the terminal may crash. The problem may be elsewhere.
 

you are using local variables. These are on the stack and not on the heap and therefore will be newly initialized each time the function is called. Make them global or static.


Edit: Forget what i wrote (although it is correct, it does not apply to your posting). I could swear the first time i looked into this thread I have seen local variables but now the code looks ok. Maybe i was too tired. Your code should work already!

Reason: