Download MetaTrader 5
To add comments, please log in or register
Publish your task in Freelance service and developers will execute your order.
doc
271
doc 2014.04.25 13:24 

Good morning all,

I have 10 datetime, and I wanna know which of these is the nearest to current time, which formula could I use?

Thanks for support. 

Rodrigo Malacarne
Moderator
9604
Rodrigo Malacarne 2014.04.25 13:43  
dr.house7:

Good morning all,

I have 10 datetime, and I wanna know which of these is the nearest to current time, which formula could I use?

Thanks for support. 

Hi dr.house7,

can you show us any effort attempt?

Have you tryied anything so far? Do you have any piece of code to show us?

If you don't have anything to show, so it's better to search at the Code Base or post a job at the Jobs Section.

doc
271
doc 2014.04.25 14:06  
Malacarne:

Hi dr.house7,

can you show us any effort attempt?

Have you tryied anything so far? Do you have any piece of code to show us?

If you don't have anything to show, so it's better to search at the Code Base or post a job at the Jobs Section.

funny
Alain Verleyen
Moderator
28651
Alain Verleyen 2014.04.25 16:02  
dr.house7:
funny

Hi, Mister House, why funny ? Do you want code for free

There is no direct formula I think. Is your 10 datetime are in an array ? Create a loop to compare each datetime to current time  and keep the datetime which is closer to current time.

If you post your code, you will get help, sure.

doc
271
doc 2014.04.25 16:58  
angevoyageur:

Hi, Mister House, why funny ? Do you want code for free

There is no direct formula I think. Is your 10 datetime are in an array ? Create a loop to compare each datetime to current time  and keep the datetime which is closer to current time.

If you post your code, you will get help, sure.

This is exactly the reply i was looking for, thanks Ange!

p.s.

I always coded for free, on tsd forum 

doc
271
doc 2014.04.25 19:36  

ok here is the code:

int touchedline[10];
int temp = 0;

touchedline[0]=doc1Time;
touchedline[1]=doc2Time;
touchedline[2]=doc3Time;
touchedline[3]=doc4Time;
touchedline[4]=doc5Time;
touchedline[5]=doc6Time;
touchedline[6]=doc7Time;
touchedline[7]=doc8Time;
touchedline[8]=doc9Time;
touchedline[9]=doc10Time;


    for(int i=0;i<10;i++)
    {
        if(touchedline[i]>temp)
        temp=touchedline[i]; 
    }
 

 doc1Time, doc2Time, doc3Time, ...etc. are datetime

with this formula I got the last touched time but not the number of the object array used...how could I know the exact last  touchedline[x] used?

I need to know which object is the highest value, touchedline[0] or touchedline[1] or touchedline[3] etc.

Thanks for support

 

doc 

Alain Verleyen
Moderator
28651
Alain Verleyen 2014.04.25 20:49  
dr.house7:

This is exactly the reply i was looking for, thanks Ange!

p.s.

I always coded for free, on tsd forum 

Everyone is free to code for free

But the tradition on mql4.com and mql5.com forum is to help people who share their code and show their attempts.

   ...
   int highest=-1;

   for(int i=0;i<10;i++)
     {
      if(touchedline[i]>temp)
        {
         highest=i;
         temp=touchedline[i];
        }
     }

This will give you the index of the highest value, and the "nearest to current time" provided that all date touchedline[] values are inferior to current time.

You can also use ArrayMaximum().

doc
271
doc 2014.04.26 00:40  
angevoyageur:

Everyone is free to code for free

But the tradition on mql4.com and mql5.com forum is to help people who share their code and show their attempts.

This will give you the index of the highest value, and the "nearest to current time" provided that all date touchedline[] values are inferior to current time.

You can also use ArrayMaximum().

:D

Thank you very much...I used  "int highest=0;" in my previous try,that was my problem.

Have a nice weekend!

 

doc 

doc
271
doc 2014.04.27 12:41  
angevoyageur:

Everyone is free to code for free

But the tradition on mql4.com and mql5.com forum is to help people who share their code and show their attempts.

This will give you the index of the highest value, and the "nearest to current time" provided that all date touchedline[] values are inferior to current time.

You can also use ArrayMaximum().

 

Good morning and nice sunday!

I hope you could guide me in the correct way again...I need to get the previous "highest" not only the current, how could I proceed?

Thanks for any help

 

doc 

Alain Verleyen
Moderator
28651
Alain Verleyen 2014.04.27 13:11  
dr.house7:

 

Good morning and nice sunday!

I hope you could guide me in the correct way again...I need to get the previous "highest" not only the current, how could I proceed?

Thanks for any help

 

doc 

Something like that ?

   ...
   int highest=-1,previousHighest=-1;

   for(int i=0;i<10;i++)
     {
      if(touchedline[i]>temp)
        {
         previousHighest=highest;
         highest=i;
         temp=touchedline[i];
        }
     }
Only a solution among others.
doc
271
doc 2014.04.27 17:25  
angevoyageur:

Something like that ?

Only a solution among others.

thanks alot it works like a charm!

but it's a bit strange to understand :) 

/ /1234
To add comments, please log in or register