Highest/Lowest code not working!

 

So I have an EA that runs at 7am every day and gets the highest and lowest open/close times in the last 12 hours. However, it's not working properly and instead runs the code for the last 36+ hours (I can't identify exactly how many hours but it definitely isn't 12!)

Any ideas?

Here's my code:

double open[], close[];
double SessionLow;
double SessionHigh;
 
CopyOpen(_Symbol,PERIOD_H1,1,12,open);
CopyClose(_Symbol,PERIOD_H1,1,12,close);
SessionLow = MathMin(open[ArrayMinimum(open,WHOLE_ARRAY,0)],close[ArrayMinimum(close,WHOLE_ARRAY,0)]);
SessionHigh = MathMax(open[ArrayMaximum(open,WHOLE_ARRAY,0)],close[ArrayMaximum(close,WHOLE_ARRAY,0)]);

When calling SessionHigh or SessionLow I'd expect the script to get the highest and lowest open/close in the last 12 hours but it isn't. It's running at 7am but the returned values aren't correct.

 
Azeem Ibrahim :

So I have an EA that runs at 7am every day and gets the highest and lowest open/close times in the last 12 hours. However, it's not working properly and instead runs the code for the last 36+ hours (I can't identify exactly how many hours but it definitely isn't 12!)

Any ideas?

Here's my code:

When calling SessionHigh or SessionLow I'd expect the script to get the highest and lowest open/close in the last 12 hours but it isn't. It's running at 7am but the returned values aren't correct.

Read the MQL5 help and do not confuse variables in places:

ArrayMinimum

int  ArrayMinimum(
   const void&   array[],             // array for search
   int           start=0,             // index to start checking with
   int           count=WHOLE_ARRAY    // number of checked elements
   );


ArrayMaximum

int  ArrayMaximum(
   const void&   array[],             // array for search
   int           start=0,             // index to start checking with
   int           count=WHOLE_ARRAY    // number of checked elements
   );


Documentation on MQL5: Array Functions / ArrayMinimum
Documentation on MQL5: Array Functions / ArrayMinimum
  • www.mql5.com
ArrayMinimum - Array Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov:

Read the MQL5 help and do not confuse variables in places:

ArrayMinimum


ArrayMaximum


I have read the documentation, and the code is correct but still not working. Could it be a weekend issue?

Code has been done in MQL4 - https://docs.mql4.com/array/arrayminimum

ArrayMinimum - Array Functions - MQL4 Reference
ArrayMinimum - Array Functions - MQL4 Reference
  • docs.mql4.com
ArrayMinimum - Array Functions - MQL4 Reference
 
Azeem Ibrahim :

I have read the documentation, and the code is correct but still not working. Could it be a weekend issue?

Code has been done in MQL4 - https://docs.mql4.com/array/arrayminimum

You are on the MQL5 forum. You write in the main section - that's why you get answers in MQL5. If you are using an old terminal, write only in a special section: MQL4 and MetaTrader 4 .

I'll postpone your topic.

 
Vladimir Karputov:

You are on the MQL5 forum. You write in the main section - that's why you get answers in MQL5. If you are using an old terminal, write only in a special section: MQL4 and MetaTrader 4 .

I'll postpone your topic.

Thank you - apologies.

 

Any ideas anyone?


I have the EA running simultaneously on 4 different charts and it's returning different values for SessionLow and SessionHigh times??