Get an Array out from a Structure

To add comments, please log in or register
claudiocaguiar
8
claudiocaguiar  
I would like to get an array of last tick info from a MqlTick strucure to use with ArrayMaximum. I gey the MqlTick array/structure with CopyTicksRange, but I do not know how to get an array with only the value of the last ticks out of the complete structure...
MqlTick tick_array2[];
datetime now = TimeCurrent();
datetime before = now-15;

if(CopyTicksRange(MYSYMBOL,tick_array2,COPY_TICKS_TRADE,before*1000, now*1000)==-1)
{Alert("Error CopyTicksRange = ", GetLastError());}

int indexmax = ArrayMaximum(tick_array2[].last????,0, WHOLE_ARRAY);

I am obviously not an expericenced programmer.. :-)

Carl Schreiber
Moderator
7073
Carl Schreiber  
ArrayMaximum() only can take numerical arrays (double, int, ..) not structures - you have to code your own function that loops through all elements of the array.
Ernst Van Der Merwe
5752
Ernst Van Der Merwe  
   int indexmax = ArrayMax(tick_array2,0, WHOLE_ARRAY);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int ArrayMax(const MqlTick &array[],int start,int count=WHOLE_ARRAY)
  {
   int size=ArraySize(array);
   if(count==WHOLE_ARRAY)
      count=size-start;
   if(!size || start<0 || (count+=start)>size)
      return(-1);
   int max=start;
//---
   for(int i=start;i<count;i++)
      if(array[max].last<array[i].last)
         max=i;
//---
   return(max);
  }
//+------------------------------------------------------------------+
To add comments, please log in or register