I wonder if there is a function to read a var that its name is constructed with StringConcatenate()
Let say we have 16 external variables called 'trade1' to 'trade16'.
Each such var holds an integer number that is a valid OrderTicket() from my pool of running trades.
l run a loop 'for j=1 to 16..' and using StringConcatenate() to create the external vars names.
let say I place the constructed var name into to a "normal" var (string) name: 'trade_x'
How do I get the value of those 'trade1' to 'trade16' through this process?
Because, if I'll ask 'trade_x' for its value?
the answer will be the name of those 'trade1' to 'trade16'. not their values.
James
I wonder if there is a function to read a var that its name is constructed with StringConcatenate()
No.
Just copy the extern variables to an array . . . and then use the array
Try functions StringArrayLoad and StringArrayWrite from library StringArraySuite.mqh (download from https://www.mql5.com/en/code/7791 and place in sub-directory "experts\include").
For a sample look at StringArraySuiteSample (download or view at https://www.mql5.com/en/code/8708 )
Try functions StringArrayLoad and StringArrayWrite from library StringArraySuite.mqh (download from https://www.mql5.com/en/code/7791 and place in sub-directory "experts\include").
For a sample look at StringArraySuiteSample (download or view at https://www.mql5.com/en/code/8708 )
#include <StringArraySuite.mqh> // pull in the library of functions //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { int iTicket[5] = { 1111, 2222, 3333, 4444, 55555 }; int iCount = ArrayRange(iTicket, 0); // determine number of Tickets dynamically // export values to external file string A[][2]; ArrayResize(A, iCount); for(int i = 0; i < iCount; i++) { A[i][0] = "trade" + i + " "; A[i][1] = iTicket[i]; } StringArrayWrite(A, "testArrayWrite.csv"); // import values from external file string B[][2]; iCount = StringArrayLoad("testArrayWrite.csv", B, 2); for(i = 0; i < iCount; i++) { Print( B[i][0], B[i][1] ); } return(0); }
I wonder if there is a function to read a var that its name is constructed with StringConcatenate()
James
I'm not sure if I have your request exactly understood, but if you convert ticket numbers (int) to strings and concatenate them then you can extract them using StringSubstr to chop the string up and then use StrToInteger to restore the ints. But I would use some sort of delimiter between the strings as you concatenate them, eg *
Otherwise 1, 21, 2345, would be difficult to un-concatenate "1212345" but "1*21*2345*" would be straightforward.
I think this is the key phrase . . .
"let say I place the constructed var name into to a "normal" var (string) called 'trade_x'"
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Note: AFAIK, arrays not allowed as external variables
So, let say we have 16 external variables called 'trade1' to 'trade16'.Each such var holds an integer number that is a valid OrderTicket() from my pool of running trades.
l run a loop 'for j=1 to 16..' and using StringConcatenate() to create the external var names.
let say I place the constructed var name into to a "normal" var (string) called 'trade_x'
How do I get the value of those 'trade1' to 'trade16' through this process?
Because, if I'll ask 'trade_x' for its value..
the answer will be the name of those 'trade1' to 'trade16'. not their values.
James