Something is wrong! Array: how to assign double values?

 

Hello, i'm trying to code a piece that looks for the Maximum and Minimum Open and Close values of the last 4 bars.

The idea is to put all values (8) in an array and then use https://docs.mql4.com/array/arraymaximum and https://docs.mql4.com/array/arrayminimum,

but something is wrong: it doesn't work. When executing, only the CHECK alert shows up... like if the array element can't be assigned. Can you help please?

      double price_array[8];
      int arrayIndex = -1;
      for (int i=1; i<=4; i++)
      {
         Alert("CHECK");
         price_array[arrayIndex++] = iClose(NULL,15,i);
         Alert("iClose: " + iClose(NULL,15,i));
         price_array[arrayIndex++] = iOpen(NULL,15,i);
      }
      int maxValueIdx=ArrayMaximum(price_array,WHOLE_ARRAY,0);
      Alert("Max value = ",price_array[maxValueIdx]," at index=",maxValueIdx);
      int minValueIdx=ArrayMinimum(price_array,WHOLE_ARRAY,0);
      Alert("Min value = ",price_array[minValueIdx]," at index=",minValueIdx);
 
int arrayIndex = 0;

using ++ after a variable means that the existing value is used and THEN the variable is increased by 1.

So you were trying to place a value in price_array[-1]

 
Thank you..
 

double j(string m,int n, int tipe)
double t=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()!=Symbol() || OrderComment()!=Magic )||OrderType()!=tipe continue;
//if(IsDemo())
{if(n==0)t++;if(n==1)t=OrderLots()*2;
if(n==2)t=OrderMagicNumber();
if(n==3)t=OrderStopLoss();
}
}return(t);
}

double ju(){return(j(k,0,0)+j(k,0,1)+j(k,0,2)+j(k,0,3)+j(k,0,4)+j(k,0,5));}
double jum(){return(j(kk,0,0)+j(kk,0,1)+j(kk,0,2)+j(kk,0,3)+j(kk,0,4)+j(kk,0,5));}

 

does anyone can help me with this i got warning

2;116;C:\Program Files\MetaTrader-IKOfx\MQL4\Experts\kelner1.mq4;147:9;'(' - function definition unexpected
2;75;C:\Program Files\MetaTrader-IKOfx\MQL4\Experts\kelner1.mq4;152:69;'tipe' - variable not defined
2;116;C:\Program Files\MetaTrader-IKOfx\MQL4\Experts\kelner1.mq4;161:10;'(' - function definition unexpected
>Exit code: 3

double j(string m,int n, int tipe)
double t=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()!=Symbol() || OrderComment()!=Magic )||OrderType()!=tipe continue;
//if(IsDemo())
{if(n==0)t++;if(n==1)t=OrderLots()*2;
if(n==2)t=OrderMagicNumber();
if(n==3)t=OrderStopLoss();
}
}return(t);
}

double ju(){return(j(k,0,0)+j(k,0,1)+j(k,0,2)+j(k,0,3)+j(k,0,4)+j(k,0,5));}
double jum(){return(j(kk,0,0)+j(kk,0,1)+j(kk,0,2)+j(kk,0,3)+j(kk,0,4)+j(kk,0,5));}

 
euricks008:

does anyone can help me with this i got warning

1) Would you mind to use the SRC-Button beside the camera?

2 ) Please have a look at other source code google "best practice programming" it'll help you a lot a) not to make those errors and b) detecting them quickly!

Paste this in the editor and you'll find the problem easily:

double j(string m,int n, int tipe)
   double t=0;
   for(int i=0; i<OrdersTotal(); i++){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      if(OrderSymbol()!=Symbol() || OrderComment()!=Magic )||OrderType()!=tipe continue;
      //if(IsDemo())
      {  if(n==0)t++;if(n==1)t=OrderLots()*2;
         if(n==2)t=OrderMagicNumber();
         if(n==3)t=OrderStopLoss();
      }
   }
   return(t);
} // <= where is the opening bracket?

double ju(){
   return(j(k,0,0)+j(k,0,1)+j(k,0,2)+j(k,0,3)+j(k,0,4)+j(k,0,5));
}
double jum(){
   return(j(kk,0,0)+j(kk,0,1)+j(kk,0,2)+j(kk,0,3)+j(kk,0,4)+j(kk,0,5));
}

But there is more to correct!!

Reason: