Michalis Phylactou: Can anyone recommend a more efficient way to achieve this .
No switch, no for.
function_1(); function_2(); function_3(); ⋮
Here is an attempt of calling functions by indexes.
#property strict #property indicator_chart_window //----------------------- interface myIntrf{ void fct(); }; //---------------------- class fct1:public myIntrf{ public: fct1(){}; ~fct1(){}; void fct(){Print("my function1");}; }; //----------------------- class fct2:public myIntrf{ public: fct2(){}; ~fct2(){}; void fct(){Print("my function2");}; }; //------------------------ class fct3:public myIntrf{ public: fct3(){}; ~fct3(){}; void fct(){Print("my function3");}; }; //----------------------- myIntrf *fctArray[3]; //+------------------------------------------------------------------+ int OnInit(){ fctArray[0]=new fct1; fctArray[1]=new fct2; fctArray[2]=new fct3; return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { for (int i=0; i<3;i++) fctArray[i].fct(); return(rates_total); } //---------------------------------------------
I'm sure more accurate codes can also be found
![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
Hello everyone.
I am trying to write an EA that has a loop and for each iteration I want it to run a different function.
Each function contains some criteria to be checked and its operations are irrelevant to each other so calling function(i) will not do anything.
Naturally I could use a switch function as follows.
Can anyone recommend a more efficient way to achieve this .
I have seen dynamic indexing is not possible
If possible on each iteration to avoid running the whole switch from the first possible element .
I am thinking something along the lines of referencing using a constant the previous iteration index so the next iteration would not begin looking for the function from all the functions . Saving the functions in external file if it would provide any benefit.
Any feedback welcome.