Array Minimum Calc Error

 

Hi all,


i'm trying to calculate the minimum value of an array but the following error occurs: EURUSD,H4: incorrect start position 0 for ArrayMinimum function

Please find below the code that i'm using: 

int ArrayCalcMin()
{   
   datetime Timeorder=LastOrderTime();
   datetime Timeahora=TimeCurrent();
   datetime Times=Timeahora-Timeorder;

   int m = TimeMinute(Times);
   int h = TimeHour(Times);
   int bars = ((h*60)+m)/240;
   int malookback=bars;

   Print("Bars value : ",bars);
   Print("M value : ",m);
   Print("H value : ",h);
   Print("Times value : ",Times);
   
 
   double madaily[];
   ArrayInitialize(madaily,0);
   
   double dllv;
   
   for(int i = 0; i < malookback; i++)
   
   {
   
   madaily[i] = iCustom(NULL,0,"Scolor8",0,i);
      
   }
   dllv = iCustom(NULL,0,"Scolor8",0,
          ArrayMinimum(madaily,WHOLE_ARRAY,0));
  
  Print("Minimum value : ",dllv);
   
   if (dllv < 50){return(1);malookback=0; }
   else {return(0);malookback=0;}
   
}

Please could you gime some tip in how can i solve this?

thank you.

KR

 
What is the return value of iCustom?

https://www.mql5.com/de/docs/indicators/icustom

And how is this return value to be used?


 
Pinto André:

Hi all,


i'm trying to calculate the minimum value of an array but the following error occurs: EURUSD,H4: incorrect start position 0 for ArrayMinimum function

Please find below the code that i'm using: 

Please could you gime some tip in how can i solve this?

thank you.

KR

Your count is zero, your start is whole array..is that intentional?
 
   double madaily[];
   ArrayInitialize(madaily,0);

Where do you size the array?


   Always use
   #property strict
   in your codes.
   When starting a project use the "New" button top left of the editor. #property strict will be included automatically.
 

Hi all,

Thank you in advance.

So what i are trying to determine is the low value of the stochcastic value (provided by the icustom) between the last trade until now.

If the minimun value is below 50 the return is 1 else 0.

thank you.

AP

 
Pinto André:

Hi all,

Thank you in advance.

So what i are trying to determine is the low value of the stochcastic value (provided by the icustom) between the last trade until now.

If the minimun value is below 50 the return is 1 else 0.

thank you.

AP

You want us to solve your issue, right?

You could go and read the docs, but its  so much more convenient to ask....


// Local init
double indicator_values[];
const int h_indicator = iCustom(....);

CopyBuffer(h_indicator, ..., indicator_values);
const int min_val_index = ArrayMinimum(indicator_values, 0);

if(indicator_values[min_val_index] < 50)
{
        // *** Condition met *** //
	return(0x01);
}

return(0x00);


Ohh, as a challenge, this code is for mql5....

 

Thank you Dominik, every help is welcome.

I really tried reading the documentation, but i'm stuck in this issue.

Nonetheless, could you point me to right direction for mql4? 

Also in the code that you attached, in the indicator_values, how do you determine the length of the array? 

in this case i'm trying to calculate the distance between the last order and now().

Regards.

AP

 
Pinto André:

Did you bother to read my post?

Keith Watford:

Where do you size the array?


   Always use
   #property strict
   in your codes.
   When starting a project use the "New" button top left of the editor. #property strict will be included automatically.
 

Hi Keith,

The size of the array depends on the number of bars between the last trade and the time current() ( converted in 4H timeframe). 

Is that what you are asking?

datetime Timeorder=LastOrderTime();
datetime Timeahora=TimeCurrent();
datetime Times=Timeahora-Timeorder;

   int m = TimeMinute(Times);
   int h = TimeHour(Times);
   int bars = ((h*60)+m)/240;
   int malookback=bars;

Thank you.

 
Pinto André:

Hi Keith,

The size of the array depends on the number of bars between the last trade and the time current() ( converted in 4H timeframe). 

Is that what you are asking?

Thank you.

No, I am asking where do you size the array?

 

Hi again,

I think that should be here -> 

 double madaily[];

I've put a random value between the [] as 1.000 and the function works. but I don't really know what is means or how can i calculate it.

Now I see that the bar count isn't correct. I will double check again the calculation.

Please let me know if is anything else that i can improve in the code. 

Thank you.

AP

Reason: