is it possible to return an array from a function ? - page 2

 
William Roeder:

w.value[index] plus you are now responsible for releasing the class on unload (but as written, not on deinit/init EA cycles.) Avoid!

Avoid? Nah...

#include <arrays/arraydouble.mqh>

void OnStart() {
   CArrayDouble *arr = getClosePrices(10);
   for (int i=arr.Total()-1; i>=0; --i) {
      Print(string(arr[i]));
   }   
}
//+------------------------------------------------------------------+

CArrayDouble* getClosePrices(int count, string symbol=NULL, ENUM_TIMEFRAMES tf=PERIOD_CURRENT) {
   static CArrayDouble result_array;
   result_array.Clear();
   double prices[];
   ArraySetAsSeries(prices, true);
   int size = CopyClose(symbol == NULL ? _Symbol : symbol, tf, 0, count, prices);
   result_array.AssignArray(prices);
   return &result_array;
}