Problem with ArrayMaximum() function

 
hi...
i try to create multi timeframe indicator, later, i want to apply it to my ea
i use copyhigh() and copylow() functions to get data.

but when i use arraymaximun an minimum function,
it look like error

please tell me what should i do

here's the code

#property version   "1.00"
#property indicator_separate_window
#property indicator_plots 0
//---
#define        TIMEFRAMES  8
#define        INDITOTAL   3

ENUM_TIMEFRAMES   MainTF[TIMEFRAMES]={
                     PERIOD_M5,  PERIOD_M15, PERIOD_M30, PERIOD_H1,  PERIOD_H4,  PERIOD_D1,  PERIOD_W1,  PERIOD_MN1};

double         resultData[TIMEFRAMES][INDITOTAL][2];

string         comstring,shortName;
//------------------------------------------------------------------//
int OnInit() {
   shortName   = MQLInfoString(MQL_PROGRAM_NAME);
   
   return(INIT_SUCCEEDED);
  }
//------------------------------------------------------------------//
void OnDeinit(const int reason) {
   Comment("");
   ChartRedraw();
  }
//------------------------------------------------------------------//
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {
   //---
   comstring = shortName;
   getData();
   
   
   Comment(comstring);
   return(rates_total);
  }
//------------------------------------------------------------------//
void getData() {
   static bool calculated=false;
   if(calculated == true) return;
   
   double   gHigh[],gLow[];
   int      tBars;
   
   static int j=0;
   while(j<TIMEFRAMES) {
      tBars = iBars(_Symbol,MainTF[j]);
      if(tBars <=0) return;
      if(CopyHigh(_Symbol,MainTF[j],0,tBars,gHigh) <=0) return;
      if(CopyLow(_Symbol,MainTF[j],0,tBars,gLow) <=0) return;
      
      int lastHi=0,lastLo=0;
      double _high   = gHigh[lastHi];
      double _low    = gLow[lastLo];
      
      for(int k=1; k<tBars; k++) {
         if(gHigh[k] > _high) {
            lastLo = ArrayMinimum(gLow,lastHi,(k-lastHi)+1);
           }
         if(gLow[k] < _low) {
            lastHi = ArrayMaximum(gHigh,lastLo,(k-lastLo)+1);
           }
        }
      
      Alert(lastHi+" --- "+lastLo);
      
      ArrayFree(gHigh);
      ArrayFree(gLow);
      
      j++;
     }
   calculated=true;
  }
//------------------------------------------------------------------//
 
Are you trying to find the most recent high and low ? (swing)
 
Lorentzos Roussos #:
Are you trying to find the most recent high and low ? (swing)



yes...
but i get no value from array maximum function

the comment() also disapear when i run the code..

thank you for your help

 
      double _high   = gHigh[lastHi];
      double _low    = gLow[lastLo];

You haven't set the array direction before filling. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
          Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5

 
William Roeder #:

You haven't set the array direction before filling. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
          Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5

thanks for your answer..

i have set the array as series array..
but now i got my terminal freezed..

i think the problem is the value of "k-lastHi" or "lastHi-k" in series array..
if i replace it with a number, it work..
but when i use the "k-lastHi", it freezed
Files:
qqq.png  84 kb
 
i think the problem is the amount of tBars...
my old machine can not handle with large amount bars calculation..
when i reduce tbar to max 1000,, its run...

theres no problem with the arraymaximum function..
its my computer fault..

sorry for that and thanks for your help..
Reason: