How to index the Open Trades symbols (in a Buffer) ? (MT4)

 

Hi coders, I'm learning coding now.


Pertaining to this post that quoted by "nicholish en" : https://www.mql5.com/en/forum/305424#comment_10829666
for (int i=0; i<symbols.Total(); i++)

Print(symbols[i]);

From my understanding, the "symbols" is a buffer to store all the open trades symbols. Let's say there are 5 symbols that with open orders, is there a way to index the open trades symbols and to avoid using the [i] so that if I want to get the iHigh price for all the open trades symbols, such as :-

Print(DoubleToStr(iHigh(symbols,1440,1),5));
// expected output would be the High price of the 5 symbols

How to "convert" the symbols[i] to symbols ? Thanks


FYI, I tried to firstly to "convert" as follows :-

   string oSym="";
   for(int i=0; i<symbols.Total(); i++) oSym=symbols[i];

   Print(oSym+" High "+DoubleToStr(iHigh(oSym,1440,1),5));

but the output only has 1 symbol (the first symbol), the other 4 symbols are not shown, why ?

Remove duplicates
Remove duplicates
  • 2019.03.02
  • Florian Riedrich
  • www.mql5.com
Hi, I want to get all Symbols in my present orderlist in an array. But if the symbol is already in the list, the loop must take the next one...
[Deleted]  

You need to use brackets: { ... }

   string oSym="";
   for(int i=0; i<symbols.Total(); i++) 
	{
		oSym=symbols[i];
		Print(oSym+" High "+DoubleToStr(iHigh(oSym,1440,1),5));
	}
 
Yashar Seyyedin #:

You need to use brackets: { ... }

Thanks Yashar. My intention is to make the "oSym" outside the bracket, so that the "oSym" can even be used to run loops for the 5 symbols (presuming there are 5 symbols that with open orders) such as below :-

   int obStoF5Sf=0; for(int i=0; i<=100; i++) {
   double cSto0=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i), cSto1=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+1),
   cSto2=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+2), cSto3=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+3),
   cSto4=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+4);
   if(cSto0<cSto1 && cSto1>=cSto2 && cSto2>cSto3 && cSto3>cSto4 && cSto1>80) {
      obStoF5Sf=i;
      break;
      }
   } // to get Overbought Shift

   Print(oSym+" OB Sto Sf : "+IntegerToString(obStoF5Sf));

Would you be able to help to "convert" the symbols[i] into oSym and sort the 5 oSym according to MODE_ASCEND ? What are the coding steps to do so ? Thanks

[Deleted]  

I do not understand what you mean but I guess you are looking for such a thing...

   int obStoF5Sf=0; 
   for(int j=0; j<symbols.Total(); j++) 
   {
      string oSym=symbols[j];
      for(int i=0; i<=100; i++) 
      {
         double cSto0=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i), cSto1=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+1),
         cSto2=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+2), cSto3=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+3),
         cSto4=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+4);
         if(cSto0<cSto1 && cSto1>=cSto2 && cSto2>cSto3 && cSto3>cSto4 && cSto1>80) 
         {
            obStoF5Sf=i;
            break;
         }
      }   
   }
 
Yashar Seyyedin #:

I do not understand what you mean but I guess you are looking for such a thing...

Hi Yashar, thanks for your kindness to help.

As we know, the symbols with open orders are all stored in the buffer symbols[i]. Let's say there are 5 symbols that with open orders : AUDJPY, EURJPY, GBPUSD, USDCHF, XAUUSD

The outputs of below Prints are printing the 5 symbols' values respectively.

Print(oSym+" High "+DoubleToStr(iHigh(oSym,1440,1),5));
Print(oSym+" OB Sto Sf : "+IntegerToString(obStoF5Sf));
My mission : prior to the 2 Prints above, I intend to "convert" the symbols[i] inro a string variable "oSym" first and this "oSym" will keep on "rotating" the 5 symbols above (to index the symbols) :-
   string oSym="";
   for(int i=0; i<opSym.Total(); i++) { ... } // I don't know what would be the coding steps to do it ...

If the above variable "oSym" is resolved, only then I will start carrying out the 2 Prints.

I hope you can understand my mission ...

[Deleted]  
   int obStoF5Sf=-1; 
   int symIndex=-1;
   for(int j=0; j<symbols.Total(); j++) 
   {
      string oSym=symbols[j];
      for(int i=0; i<=100; i++) 
      {
         double cSto0=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i), cSto1=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+1),
         cSto2=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+2), cSto3=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+3),
         cSto4=iStochastic(oSym,60,5,3,3,0,0,MODE_MAIN,i+4);
         if(cSto0<cSto1 && cSto1>=cSto2 && cSto2>cSto3 && cSto3>cSto4 && cSto1>80) 
         {
            obStoF5Sf=i;
	    symIndex=j;
            break;
         }
      }   
   }
...
...



Print(symbols[symIndex]+" High "+DoubleToStr(iHigh(symbols[symIndex],1440,1),5));
Print(symbols[symIndex]+" OB Sto Sf : "+IntegerToString(obStoF5Sf));
 
Yashar Seyyedin #:
Print(symbols[symIndex]+" High "+DoubleToStr(iHigh(symbols[symIndex],1440,1),5)); Print(symbols[symIndex]+" OB Sto Sf : "+IntegerToString(obStoF5Sf));

Would it be possible to use "oSym" instead of "symbols[symIndex]" such as below ? The "oSym" will keep on "rotating" the 5 symbols.

Print(oSym+" High "+DoubleToStr(iHigh(oSym,1440,1),5));
Print(oSym+" OB Sto Sf : "+IntegerToString(obStoF5Sf));
[Deleted]  
Chin Min Wan #:

Would it be possible to use "oSym" instead of "symbols[symIndex]" such as below ?

Does it make a difference really?
 
Yashar Seyyedin #:
Does it make a difference really?

Yes, it is very important to me as I may run more than 20 different loops in my entry and exit signals, that's why I need to firstly to get a "rotating" string oSym variable for my purposes. Hopefully you can help, thank you.

 
Yashar Seyyedin #:

Hi Yashar, just FYI, I'm only busy with the Entry and Exit functions to set conditions for signals to OrderSend() and OrderClose().

I tried to create a function such as ...

void OpOrd(string symbols) { ... }

to migrate all the open orders calculations so that the outputs can be called into the Entry and Exit functions for my signals conditions calculations. Inside the Entry and Exit functions, I intend to use the "oSym" for loops and other calcultions ... however, I failed.

Would it be possible to code in such direction ? Thanks

[Deleted]  
Your request is totally unclear to me... You have to propose your full specification and maybe someone will be interested to help for free.