For what I think you're trying to do, you can use callbacks. You'll still need to set the variables to call them though (and be careful not to call a NULL function).
typedef int (*condCallback)(void); int condition1() { return 1; } //... 2-5 int condition6() { return 6; } void OnInit() { condCallback functions[6]; functions[0] = condition1; functions[1] = condition2; functions[2] = condition3; functions[3] = condition4; functions[4] = condition5; functions[5] = condition6; for (int i=0; i<6; i++) { Print(functions[i]()); } }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Dear fellows,
I wrote the following code to use and test various conditions. This is the concept: I will run the strategy tester from 1 to 2^10 (because I have 10 conditions, and at each test one condition can be used or can be not used).
In order to combine the conditions in all combinations possible I have written the following code, which is compiling fine.
Each condition has its own function, lets say, condition_1 is crossing of moving averages; condition_2 is today's volume greater than volumes of last 5 days, and so on...
My question to you guys, is how can I call a function inside a for loop without having to write the names of the conditions (which is what I did).
I would like to call the functions witha parameter lets say:
for(i=0 to i=20)
{
int call = condition_1 * condition_2 * condition_3 * ... * condition_20
} // somethin like that, but leaving the invocation of the functions parametrized, if you understand what I mean.
what is the way to invoke a function without having to literraly write its name. Can I call a function using a built string? for example "condition_"+"1" ?
here is the code I did: