MQ4 - StringConcatenate - how to include iOpen?

To add comments, please log in or register
Curious Mind
13
Curious Mind  

Been struggling for hours now on apparently easy task. If someone could point out my error, please? I would like to use StringConcatenate with "iOpen" (or iTime, iHigh, iLow, iClose).

EURUSD_M1_OPEN  = iOpen("EURUSD",PERIOD_M1,1); // this is the default way, working. 

Instead, I would like to avoid hard-coding the currencies part into the code. Reason: many currencies in the list and I would like to be able to swap currencies out with changing the name of currency in one place only.

To accomplish that, I am looking at the following option:

string cur_1  = "EURUSD";
double cur_1_open;

Attempt A. 
cur_1_open  = StringConcatenate(iOpen+cur_1,"PERIOD_M1","1");

Attempt B. 
cur_1_open  = StringConcatenate(iOpen+"(\"+cur_1+\",PERIOD_M1,1)");

Both attempts give me the same ERROR: 'iOpen' - undeclared identifier;

What am I doing wrong? Why is it asking for the iOpen to be "declared", if the "default" way of coding it iOpen("EURUSD",PERIOD_M1,1) does NOT ask for the iOpen to be "declared". Am I using the StringConcatenate plain wrong?

MQ4 - StringConcatenate - how to include iOpen?
MQ4 - StringConcatenate - how to include iOpen?
  • stackoverflow.com
Been struggling for hours now on apparently easy task. If someone could point out my error, please? I would like to use with "iTime" (or iOpen, iHigh, iLow, iClose). Instead, I would like to avoid hard-coding the currencies part into the code. Reason: many currencies in the list and I would like to be able to swap currencies out with changing...
Anthony Garot
2136
Anthony Garot  
Curious Mind:
Am I using the StringConcatenate plain wrong?

You don't need StringConcatenate().

Do something like this:

string cur_1 = "EURUSD"; 
double cur_1_open = iOpen(cur_1,PERIOD_M1,1);
if ( cur_1_open == 0 )
{
    Print("Error ", GetLastError());
}
Curious Mind
13
Curious Mind  
Anthony Garot:

You don't need StringConcatenate().

Do something like this:

That was it! Can't believe how I'd miss that!! Much appreciated, Anthony Garot!!
To add comments, please log in or register