Download MetaTrader 5
To add comments, please log in or register
Store your source codes in MQL5 Storage. It is secure!
pete42 2015.10.28 10:44 



I am working on a basket trading EA. So far I have written most of the code and I came to the basket BUY and SELL Buttons linked functions.


What I have so far is several arrays to build the buttons and feed the several formulas with the needed values. I now have the following to complete:


string sym[]={"EURUSD", "GBPUSD", "USDJPY", "USDCHF", "NZDUSD","AUDUSD","USDCAD"}; // already existing

string EURUSDb[]={"EURUSD", "EURGBP", "EURJPY", "EURCHF", "EURNZD", "EURAUD", "EURCAD"}; //already existing

....and more similar arrays with different symbols to create the correct basket for the remaining pairs.

In the OnChartEvent section, I want to do recognize when I click the BUY BASKET in the EUR section, for example, I want the following to be possible:

for(i=0; i<=6; i++)


obj=sym[i]+DoubleToString((i+4),0); //to match the correct denomination of the button - not of much importance in this case.

if(sparam)=obj //meaning the button has been pressed


for(r=0; r<=6; r++)

Ordersend(EURUSDb[r], .......); // this is where I have the problem! At the first run of the loop when i=0,  sym[0]=EURUSD - I can construct the array name to be called in the next function as such: sym[0]+"b". How to call the array EURUSDb[r] using basket value. I tried (sym[i]+"b")[r] to get the equivalent of EURUSDb[r] but did not work.

ObjectSetString(...OBJPROP_STATE, false);


I know it can be done with the if loop to assign manually the array to be used in the ordersend function and/or add a 2 dimentional array to the rest of the array list. I dont want to create additional lines or any additional arrays - the rest of the code is already built around the current arrays and would really not want to rewrite the whole code before it is confirmed there's no other way to achieve what I am after.

If any function exist to do what I have explained above, please show me the way or any other simple/easy workaround to this case.


I really appreciate your help.



To add comments, please log in or register