Lowest and highest price between 2 hours

 

Hello mates,

I am trying to obtain the minimum and maximum prices in a time slot and I am not getting it. I have managed to obtain the minimum and maximum between a past hour and the current hour. But for example: If I want to create an indicator that draws two horizontal lines between the minimum and maximum prices between 11:00 and 12:00, how can I obtain these prices?

I currently have this:

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[])

  {

   max = 0;

   min = 0;

   for(int i = 0; i < Bars; i++)

     {

         if(TimeCurrent() >= StringToTime("11:00") && (TimeCurrent() < StringToTime("12:00")))

           {

            max = MathMax(max,High[i]);

            min = MathMin(min,Low[i]);

            Print(Hour() + " : " + max + " - " + min);

           }

   // this is not working properly

     }


   return(rates_total);

  }

Thank you very much

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Price Constants - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Your loop is over all bars. But your if statement is constant over the same bars (TimeCurrent and Hour).

You want to find the bar indexes for your time range, and the highest high for that range. No loop required.

 
William Roeder #:

Su ciclo está sobre todas las barras. Pero su declaración if es constante en las mismas barras ( TimeCurrent y Hour ).

Desea encontrar los índices de barra para su rango de tiempo y el máximo más alto para ese rango. No se requiere bucle.

What you say is correct, but I don't know how to program that code.

How do I extract the start time or end time from each bar?
 
Ardada Marotsim #: How do I extract the start time or end time from each bar?

Perhaps you should read the manual. Time - Predefined Variables - MQL4 Reference
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

 
William Roeder #:

Perhaps you should read the manual . Time - Predefined Variables - MQL4 Reference
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

I have already read the MQL4 documentation

I see that you don't know how to answer my question either, otherwise you wouldn't have wasted your time sending me those links

thanks for nothing

 
Ardada Marotsim #: I have already read the MQL4 documentation. I see that you don't know how to answer my question either, otherwise you wouldn't have wasted your time sending me those links thanks for nothing

I can't answer for William, only for myself, and these are my observations:

Please don't take this as offensive but as a reality of the situation. From what I see from your code, it is "very bad". One can see that you have very little understanding of coding in MQL and that your code logic is very weak. So it is difficult for us to explain how you can obtain the highest and lowest when so much of your code is totally wrong.

For example, you don't seem to understand how the OnCalculate() event handler works, or how the datetime variables contain both a date and a time and that you can't just compare the times only, or that TimeCurrent() is just that (the current time of the trade server) and not the open time of the referenced bar, etc.

So, in conclusion, what I am trying to say, is that you have to dedicate some more time to learning to code in general, learning coding principals and the basics of MQL, before you can even attempt to try to understand how to code a basic indicator.

So, please do not take offence. Take it as an explanation of why it is difficult to explain all that is wrong with your code with just a few posts. The most we can do is offer links for you to read and do more research.

 
Fernando Carreiro #:

I can't answer for William, only for myself, and these are my observations:

‎Por favor, no tomen esto como ofensivo, sino como una realidad de la situación. Por lo que veo en su código, es "muy malo". Uno puede ver que tiene muy poca comprensión de la codificación en MQL y que su lógica de código es muy débil. Por lo tanto, es difícil para nosotros explicar cómo puede obtener lo más alto y lo más bajo cuando gran parte de su código es totalmente incorrecto.‎

‎Por ejemplo, parece que no entiende cómo funciona el controlador de eventos OnCalculate(), o cómo las variables ‎‎datetime‎‎ contienen una fecha y una hora y que no puede simplemente comparar solo las horas, o que TimeCurrent() es solo eso (la hora actual del servidor comercial) y no la hora de apertura de la barra a la que se hace referencia, etc.‎

‎Entonces, en conclusión, lo que estoy tratando de decir, es que tienes que dedicar algo más de tiempo a aprender a codificar en general, aprender los principios de codificación y los conceptos básicos de MQL, antes de que puedas intentar entender cómo codificar un indicador básico.‎

‎Por lo tanto, por favor, no se ofendan. Tómelo como una explicación de por qué es difícil explicar todo lo que está mal con su código con solo unas pocas publicaciones. Lo más que podemos hacer es ofrecer enlaces para que los leas y hagas más investigaciones.‎

Thanks for your answer,

I'm actually new to coding in MQL4 and I'm learning the basics right now. I know my code is bad.

In my opinion the official MQL4 documentation isn't very intuitive, and I haven't found much material outside the community. I would appreciate if you know more places to learn MQL4 apart from the official reference.

Still keep studying and learning.

All the best Fernando

 
Ardada Marotsim #: I see that you don't know how to answer my question either,
I don't? You asked:
Ardada Marotsim #: How do I extract the start time or end time from each bar?
I answered Time[i] I see you don't know how to read answers.
 
Hello William,


William Roeder #:   

How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

I think this was unnecessary.

William Roeder #:

Perhaps you should read the manual. Time - Predefined Variables - MQL4 Reference

This comment would have been enough and this bad atmosphere would not have been generated.


Ardada, as Fernando says, you need to review the MQL4 documentation in more depth.


Regards

Lowest and highest price between 2 hours
Lowest and highest price between 2 hours
  • 2022.03.15
  • www.mql5.com
Hello mates, I am trying to obtain the minimum and maximum prices in a time slot and I am not getting it...
Reason: