Read an external constructed var value?

 
I wonder if there is a function to read a var that its name is constructed with StringConcatenate()

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
 
JJF:
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 dunno the answer :(, maybe array https://docs.mql4.com/array
 
JJF:
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

 
onewithzachy:
I dunno the answer :(, maybe array https://docs.mql4.com/array
or MT4 GlobalVariables https://docs.mql4.com/globals
 

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 )

 
sxTed:

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 )

How does that help ?
 
#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 think you misunderstand what the OP is looking to do . . . he has 16 ticket numbers in 16 extern ints . . . he wants to access these variables inside a loop . .
 
James asked for external variables, StringArraySuite gives him a two dimensional string array which is easier to handle. The arrays are dynamic in size (example the number of ticket numbers). My sample above accesses the variables inside a loop.
 
JJF:
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'"

Reason: