Download MetaTrader 5
To add comments, please log in or register
1000 paid orders are executed in Freelance service. Sign up!
blustacker
13
blustacker 2016.08.17 08:29 

Hi,

Does anyone here tried to create a function that returns an array? Instead of creating a function that returns ticket number, open price for a specific logic, store all of the necessary data on array returned to a function.


Thanks.

Carl Schreiber
5940
Carl Schreiber 2016.08.17 09:15  

It's all in the docs e.g. editor's Reference (F1): "What can be returned: simple types, simple structures, object pointers."

There you'll find even examples...

Keith Watford
Moderator
7906
Keith Watford 2016.08.17 09:40  
blustacker:

Hi,

Does anyone here tried to create a function that returns an array? Instead of creating a function that returns ticket number, open price for a specific logic, store all of the necessary data on array returned to a function.


Thanks.

You cannot return an array from a function.

You can pass an array by reference to the function an it can assign new values to the array.

blustacker
13
blustacker 2016.08.17 10:12  
i tried to use vector but i think it is not supported on mql.
Fernando Carreiro
1451
Fernando Carreiro 2016.08.17 10:28  
blustacker:
i tried to use vector but i think it is not supported on mql.

Just pass an Array by reference (as stated by GumRai above)!

If you use a Dynamic array, it can even be empty before calling the function and that function can populate it or manipulate it in any way you wish it; and when the function returns, you will effectively have returned an array.

Keith Watford
Moderator
7906
Keith Watford 2016.08.17 11:23  
RemoveElement(x,as,TradesDetails);
void RemoveElement(int x,int as,Trades &array[])
  {
   for(;x<as-1;x++)
     {
      array[x].ticket=array[x+1].ticket;
      array[x].breakeven=array[x+1].breakeven;
      array[x].entry=array[x+1].entry;
      array[x].lotsize=array[x+1].lotsize;
      array[x].signal_time=array[x+1].signal_time;
      array[x].stoploss=array[x+1].stoploss;
      array[x].takeprofit=array[x+1].takeprofit;
      array[x].trail=array[x+1].trail;
     }
   ArrayResize(array,as-1);
   return;
  }

Here's an example of passing an array by reference, in this case a struct array.

/
To add comments, please log in or register