questions about the use of Array

 
Hi everyone
In the expert that  I want to write, I need to measure the strength of each currency based on a series of parameters and then determine the strongest and weakest currency.

For example, I will create the variable dollar, euro, franc, etc., and then declare the largest one based on the value as the strongest and the smallest value based on the value as the weakest.

In PHP, you can give a key and a value for each element of the array. Is it possible to do the same in MQL4 ? Thanks 

IN PHP :

$Currency['USD'] = 59;
$Currency['NZD'] = 48;
$Currency['CHF'] = 70;

Print_r($currency);

output :
Array(['USD']=>59 ['NZD']=>48 ['CHF']=>70)
 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Shahriar Soltani:
Hi everyone
In the expert that  I want to write, I need to measure the strength of each currency based on a series of parameters and then determine the strongest and weakest currency.

For example, I will create the variable dollar, euro, franc, etc., and then declare the largest one based on the value as the strongest and the smallest value based on the value as the weakest.

In PHP, you can give a key and a value for each element of the array. Is it possible to do the same in MQL4 ? Thanks 

Not as straight forward as PHP, but some things you could consider are:

   int inArray[3] = {};


//Method 1 - constants
#define d_USD 0
#define d_NZD 1
#define d_CHF 2

   inArray[d_USD] = 59;
   inArray[d_NZD] = 48;
   inArray[d_CHF] = 70;

   ArrayPrint(inArray);

   PrintFormat("d_USD = %d", inArray[d_USD]);
   PrintFormat("d_NZD = %d", inArray[d_NZD]);
   PrintFormat("d_CHF = %d", inArray[d_CHF]);

//Method 2 - enum
   enum
     {
      e_USD = 0,
      e_NZD = 1,
      e_CHF = 2
     };

   PrintFormat("e_USD = %d", inArray[e_USD]);
   PrintFormat("e_NZD = %d", inArray[e_NZD]);
   PrintFormat("e_CHF = %d", inArray[e_CHF]);

PS - I use MQL5 so check it works for MQL4

 
R4tna C #:

Not as straight forward as PHP, but some things you could consider are:

PS - I use MQL5 so check it works for MQL4

Thank you,  actually  I am using MQL4 and it does not have ArrayPrint() .

but the codes you wrote, were useful to me . Thanks again

 
Shahriar Soltani #:

Thank you,  actually  I am using MQL4 and it does not have ArrayPrint() .

but the codes you wrote, were useful to me . Thanks again

Thanks for confirming

 

I would create a separate array of symbols:

string symbols[]={"GOLD","AUDCAD.r"......}

And then calculate a separate array of scores and the symbol index.

double pairs[28][2];
for(int i=0;i<ArraySize(symbols);i++){
  pairs[i][0]=50 // score
  pairs[i][1]=i;  // symbol array index
}

Then you can sort pairs array by score to get the strongest to weakest. ==> ArraySort(...)

Reason: