Download MetaTrader 5
To add comments, please log in or register
One billion tasks have already been executed with MQL5 Cloud Network. Test trading robots even faster!
Stephen Reynolds
483
Stephen Reynolds 2015.06.03 16:54 
Im trying to write a short code that finds the highest value of iStochastic from the last 3 bars using the ArrayMaximum () function.
void OnInit() 
{  
   double s1 = iStochastic(_Symbol,_Period,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_MAIN,0);
   double s2 = iStochastic(_Symbol,_Period,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_MAIN,1);
   double s3 = iStochastic(_Symbol,_Period,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_MAIN,2);
      
   double num_array[3]={s1,s2,s3};   
   int maxValueIdx=ArrayMaximum(num_array,WHOLE_ARRAY,0); 
   
   double high = iHigh(NULL,0,maxValueIdx);    
   datetime time = iTime(NULL,0,maxValueIdx);
      
   bool line1 = ObjectCreate("Thumb",OBJ_ARROW_THUMB_UP,0,time,high);
}


I have tried to assign each object but the array doesn't understand the objects.

So here i'm stuck on figuring how I get ArrayMaximum () function to understand the iStochastic values.

Alain Verleyen
Moderator
28522
Alain Verleyen 2015.06.03 17:52  

Don't place this code in OnInit().

   double num_array[3];
   for(int i=0;i<3;i++)
     {
      num_array[i]=iStochastic(_Symbol,_Period,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_MAIN,i);
     }

   int maxValueIdx=ArrayMaximum(num_array,WHOLE_ARRAY,0);

   double high=iHigh(NULL,0,maxValueIdx);
   datetime time=iTime(NULL,0,maxValueIdx);

   bool line1=ObjectCreate("Thumb",OBJ_ARROW_THUMB_UP,0,time,high);
whroeder1
13596
whroeder1 2015.06.03 18:34  
 double num_array[3]={s1,s2,s3};
Only initializing with constants can use that form.
Stephen Reynolds
483
Stephen Reynolds 2015.06.03 18:42  
angevoyageur:

Don't place this code in OnInit().

Thanks!
/
To add comments, please log in or register