Function with variable number of parameters
It is currently not possible to create user defined MQL functions with a variable number of parameters. Only built-in functions can have that possibility.
class ATR{ public: ATR(COUNT len=14) : mSymbol(_Symbol), mLength(len), // cTor mTF( ENUM_TIMEFRAMES(_Period) ){} ATR(ENUM_TIMEFRAMES tf, COUNT len=14) // cTor : mSymbol(_Symbol), mLength(len), mTF(tf){} ATR(SYMBOL sym, ENUM_TIMEFRAMES tf=0, COUNT len=14) // cTor : mSymbol(sym), mLength(len), mTF(tf){} PRICE get(INDEX iBar){ return iATR(mSymbol, mTF, mLength, iBar); } private: SYMBOL mSymbol; COUNT mLength; ENUM_TIMEFRAMES mTF; }; // ATR
Hi everyone.
I need to use one fuction, but with a varible numbers of parameters, the quntity of parameters is known in advance.
In C++ for example, you use kind of void func(int a, int b, ...) and it's simple. But unfortunately I havent found any information about it in MQL4.
Any tips, how to do it?
You can also create a cascade of chained methods by returning this pointer...
template<typename T1> String* Format(T1) { ...; return &this;} template<typename T1,typename T2> String* Format(T1 var1,T2 var2) { return Format(var1).Format(var2); } template<typename T1,typename T2,typename T3> String* Format(T1 var1,T2 var2,T3 var3) { return Format(var1,var2).Format(var3); } template<typename T1,typename T2,typename T3,typename T4> String* Format(T1 var1,T2 var2,T3 var3,T4 var4) { return Format(var1,var2,var3).Format(var4); } template<typename T1,typename T2,typename T3,typename T4,typename T5> String* Format(T1 var1,T2 var2,T3 var3,T4 var4,T5 var5) { return Format(var1,var2,var3,var4).Format(var5); }
Simple
Use ARRAY
double theArray[]; int FunVariableParams( int abc, double &theArray[]){ ... do something }
Hi everyone.
I need to use one fuction, but with a varible numbers of parameters, the quntity of parameters is known in advance.
In C++ for example, you use kind of void func(int a, int b, ...) and it's simple. But unfortunately I havent found any information about it in MQL4.
Any tips, how to do it?