Download MetaTrader 5
To add comments, please log in or register
Do you wonder how to use widgets? Read the article!
manuel_campelo
45
manuel_campelo 2015.02.27 09:02 

   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
Stuart Browne
5601
Stuart Browne 2015.02.27 09:19  
Hi Manuel & welcome

Why not just load the similar input parameters (extern variables) into either single or multi-dimensional arrays then you can just loop through each index and perform the repeated calculations.

Cheers
Drazen Penic
2435
Drazen Penic 2015.02.27 11:16  

MQL has nice OO features that can be used to create very elegant and efficient solution for your problem.

But, if you don't have any experience with OO programming, learning curve can be steep. 

Stuart Browne
5601
Stuart Browne 2015.02.27 12:16  
drazen64:

MQL has nice OO features that can be used to create very elegant and efficient solution for your problem.

But, if you don't have any experience with OO programming, learning curve can be steep. 

Agree with that 100% ! I'm sure most don't use the full OOP features of MQL but the fact that you can strip it down bare is what makes it so accessible to non programmers :)
/
To add comments, please log in or register