Scalable Code. Does anyone knows...?

 

   Hi, everyone.

    I'm almost new to mql4 programming but I have been around programming some time in other languajes. I'm trying to code an EA that runs at once several Strategies but I found a problem when coding,

as all Strategies use the same program but may have different parameters, when I code I have to check all parameters one by one. Let me explain.

For instance: Strategy1_SL_pips=40;  Strategy1_Trail=true;  and so on...

                   Strategy2_SL_pips=20;  Strategy1_Trail=false;  and so on...

So when I arrive at a point where I have to use them, i need to check every single Variable by its name.

For instance: if (Strategy1_Trail) { Do stuff;}

                    if (Strategy2_Trail { Repeat code; }

In other languajes U can get a Variable's Value by its name and do things like this:

string StrategyArray[]={"Strategy1","Strategy2"...};

for (int i=0; i<ArrayRange(StrategyArray,0);i++) {

   if (GetValue(StrategyArray[i]+"_Trail")==true) { Do Stuff;}

}

Where GetValue is a function provided from the languaje.

I've seen that it can be made something like that with GlobalVariables but I didn't see how can I do with extern variables.

This issue would save me tons of repeated code and much less errors when upgrading or changing code. I would be grateful if someone tell me how to get a solution. Thanks in advance

 
  1. Copy the variables to an array in OnInit and use the array.
  2. Write a function
    bool Get_Strategy_Trail(int i){
       switch(i){
       case 1: return Strategy1_Trail;
       case 2: return Strategy2_Trail;
    }  }

Reason: