How to define global variables for each open position?

 

Hi,

I'm trying to make my first EA. I need to give each open position a variable that will be remembered until the position closes and if necessary updated if certain conditions are met with every new bar.

I believe the variable should be declared before the start() function... but how can I do this if several positions are going to be constantly opening and closing. Maybe an array could help?

Thanks a lot,

 
#define MAXOPEN 99
int Ticket[MAXOPEN]; double data1[MAXOPEN]; //...
int start(){
    int posEmpty;
    for(int pos = 0; pos < MAXOPEN; pos++) 
    if (Ticket[pos] == 0){
       posEmpty = pos;
    }
    else if (!OrderSelect(Ticket[pos], SELECT_BY_TICKET){
       Ticket[pos]=0; // Order had closed
    }
    else{
       Print("Ticket ",Ticket[pos]," data ",data1[pos]); ...
    }
    ...
    // Want to open
    Ticket[posEmpty] = OrderSend(...
    data1[posEmpty]  = ...
Note that in the case of terminal crash, power reboot, etc. existing trades and the corresponding data will be lost. At the end of start you should write all the data to a file and read the file back in on init. See persistent storage
Reason: