A quick question. Do any of you know if it is possible to create a function with a variable number of parameters that can be of any type?
In other languages this is sometimes referred to as 'paramarray'. An example in MQL4 is
int FileWrite( int handle, ...)
With the above, once you have entered a handle you can add any number of parameters of any type. Any ideas if I can write a similar function for MQL4?
Stewart
.
according to me not possible
how can a parameter be any type ???
double, int, color, bool, string, datetime.....
.
your example FileWrite is from type int
.
according to me not possible
how can a parameter be any type ???
double, int, color, bool, string, datetime.....
.
your example FileWrite is from type int
It seems FileWrite can take parameters of any type . . . not sure how but I'm pretty sure we can't replicate it. We can go part of the way, we can have a function that will accept many doubles and ints, the issue would be having a scheme to know what the last valid variable is . . .
int MyFunction(double variable1, double variable2 = 0, double variable3 = 0, double variable4 = 0, double variable5 = 0, double variable6 = 0, double variable7 = 0, double variable8 = 0, double variable9 = 0, double variable10 = 0, double variable11 = 0, double variable12 = 0 )
It seems FileWrite can take parameters of any type . . . not sure how but I'm pretty sure we can't replicate it. We can go part of the way, we can have a function that will accept many doubles and ints, the issue would be having a scheme to know what the last valid variable is . . .
Maybe I don't understand the question, but i think you make for every parameter a defination of what kind of type it is.
Then that parameter can't changed while the program is working to another kind of type.
.
MyFunction is a parameter type int (integer)
Inside this funtion there are other parameters but all have there own type defination
All the parameters inside MyFunction are type double so they be only that type...
variable1 and all the others can't be a string this way....
Yes, I feared that the answer was no. Oh well, it was worth a try asking around. Thanks guys.
For what I need, I think the closest match is taking a string array.
variable1 and all the others can't be a string this way....
They can also be used for int, colour, datetime, bool . . . but I agree, not strings.
If you read a CSV.file then it is basically all text
Date,Time,Time Zone,Currency,Event,Importance,Actual,Forecast,Previous Sun Jul 15,22:30,GMT,nzd,NZD Performance Services Index,Low,54.3,,56.6 Sun Jul 15,23:01,GMT,gbp,GBP Rightmove House Prices (MoM),Low,-1.7%,,1.0% Sun Jul 15,23:01,GMT,gbp,GBP Rightmove House Prices (YoY),Low,2.3%,,2.4% Mon Jul 16,,,cad,CAD Existing Home Sales (MoM),Low,-1.3%,,-3.1% Mon Jul 16,07:15,GMT,chf,CHF Industrial Production (YoY),Medium,1.4%,0.0%,3.6% Mon Jul 16,08:00,GMT,eur,EUR Italian Trade Balance (Total) (Euros),Low,1008M,,-200M Mon Jul 16,08:00,GMT,eur,EUR Italian Trade Balance Eu (Euros),Low,691M,,704M Mon Jul 16,08:30,GMT,eur,EUR Italian General Government Debt (MAY),Low,1966.3B,,1949.2B Mon Jul 16,09:00,GMT,eur,EUR Euro-Zone Consumer Price Index - Core (YoY),High,1.6%,1.6%,1.6%separated by,
string News[1000][10]; is used inside the newsindicator i made to read it all
and coloms are defined by
#define COLUMN_DATE 0 #define COLUMN_TIME 1 #define COLUMN_TIMEZONE 2 #define COLUMN_CURRENCY 3 #define COLUMN_DESCRIPTION 4 #define COLUMN_IMPORTANCE 5 #define COLUMN_ACTUAL 6 #define COLUMN_FORECAST 7 #define COLUMN_PREVIOUS 8 #define COLUMN_DATE_DAY_STR 0 #define COLUMN_DATE_MONTH_STR 1 #define COLUMN_DATE_DAY_INT 2
So it might be what stewart is suggesting it has to be to take a string array
Look at this thread: http://www.forexfactory.com/showthread.php?t=245303
Especially the function log() that is defined there. Apparently you just have to define the arguments of type string and then it will essentially take every type of argument.
Incidentally, this is what I used it for. You can log up to 8 messages of any type. I have a global parameter which enables or disables logging.
// Log a message to the log if logging is enabled
void LogMessage(int logHandle, bool enabled, string m1, string m2="", string m3="", string m4="", string m5="", string m6="", string m7="", string m8="")
{
if (enabled == true)
{
string m = StringConcatenate(m1, " ", m2, " ", m3, " ", m4, " ", m5, " ", m6, " ", m7, " ", m8);
m = StringTrimRight(m);
FileWrite(logHandle, TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS), m);
}
return;
}
Incidentally, this is what I used it for. You can log up to 8 messages of any type. I have a global parameter which enables or disables logging.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
A quick question. Do any of you know if it is possible to create a function with a variable number of parameters that can be of any type?
In other languages this is sometimes referred to as 'paramarray'. An example in MQL4 is
int FileWrite( int handle, ...)
With the above, once you have entered a handle you can add any number of parameters of any type. Any ideas if I can write a similar function for MQL4?
Stewart