Function return array

Back to topics list To post a new topic, please log in or register
avatar
2
blustacker 2016.08.17 10: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.

avatar
2017
gooly 2016.08.17 11: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...

avatar
Moderator
3404
GumRai 2016.08.17 11: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.

avatar
2
blustacker 2016.08.17 12:12 #
 
i tried to use vector but i think it is not supported on mql.
avatar
1197
FMIC 2016.08.17 12: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.

avatar
Moderator
3404
GumRai 2016.08.17 13: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.

Back to topics list  

To add comments, please log in or register