How to refer to a particular time - page 4

 
Agent86:
Hi
Thanks for the response

I did read your post which was regarding a time range or range / filter and I understood the conclusion but not the equations completely

By your answer I have to assume that I don't understand how to create an expression that would compare something like if(Time[1] == 7:15) in it's proper form because I don't understand the equations you posted.

You need to read what is written and figure it out . . . if you don't understand a Function look it up and read about it till you understand it. The code that WHR posted is very simple maths . . . the only thing you might not be familiar with is the % . . . it doesn't mean percentage . . . look it up, you can find it here: https://docs.mql4.com/basis/operations/math
 
RaptorUK:

You really need to start learning your way around the documentation . . .

Go to any function that uses a TimeFrame and you will see timeframe enumeration . . . and it links to here: Timeframe enumeration and that will tell you that Period_H1 is a value of 60 . . . in other words 60 minutes . . . 60 mins * 60 = seconds . . . datetimes are in seconds.


What you have coded won't work . . your time_select is NOT a datetime . . . remember, what is a datetime ? from the Documentation . . . "datetime type (integer representing the amount of seconds elapsed from midnight, 1 January, 1970)." if you want a datetime that means 7:15 am it has to be the number of seconds that have elapsed from 1 Jan 1970 to 7:15am today . . .

What you ave calculated is the number of seconds from Midnight to 7:15am this morning, and that is not a datetime.


I know this is not a datetime and I guess If I understood exactly what PERIOD_H1 I would have know that too.

I get it now I have to convert to seconds from 1,January, 1970
ok thanks
 
RaptorUK:
You need to read what is written and figure it out . . . if you don't understand a Function look it up and read about it till you understand it. The code that WHR posted is very simple maths . . . the only thing you might not be familiar with is the % . . . it doesn't mean percentage . . . look it up, you can find it here: https://docs.mql4.com/basis/operations/math
I do understand that % does not mean percent.
I did not understand the 86400 or why that was used.

I just figured this out == how many seconds in a day got it thanks
 
Thanks people

I continued to work through this and understand the various ways to conclude midnight of a particular day

Then as suggested some other methods to calculate 18hrs x 3600 which I see is the number of seconds in an hour multiplied X 18 to give me HR1800

I think I should be able to make some various time codes from this including some time codes for a particular time not only a range

Thanks again
 
Here is some of my progress, for a selectible time and/or time range

Incomplete and crude but at least I do understand all the posts now thanks a bunch

//+------------------------------------------------------------------+
//|                                         15min_straddle_timer.mq4 |
//|                                     Agent86  15 straddle timer   |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Agent86"


//---- input parameters
extern double    TakeProfit=20.0;
extern double    Lots=0.1;
extern double    StopLoss=10.0;
extern int MagicNumber=1586;

//Time Select and Range select IE: extHour=7; and extMinutes=15; means 7:15am
//Note using the 24hour clock means extHour=13; means 1:00pm fyi
extern int  extHour=7;
extern int  extMinutes=15;

//++++ These are adjusted for 5 digit brokers.

int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)

    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   if (Digits == 5 || Digits == 3)
   {    // Adjust for five (5) digit brokers.
      pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
   } 
   else 
    {    
      pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; 
    }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
     
   
    
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
   
    
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

datetime now = Time[0],
         bod = now - now % 86400,
         Time_Select = bod + extHour*3600+extMinutes,
         HR1800 = bod + 18*3600,  //I'll make extern for this too
         HR2100 = bod + 21*3600;  //and this
         
if (Time[1] == Time_Select)
   {
   double Low_Mark = Low[1] - 20*pips2dbl,
          High_Mark = High[1] + 20*pips2dbl;
   Print (Low[1], " = Low ", Low_Mark," = Low_Mark"); 
   Print (TimeToStr(Time[1])," Low =", Low[1], " High =", High[1]);
   }
   {
   }
   
//if (Time[1] >= HR1800 && Time[1] < HR2100)
      
          
   return(0);
  }    

//+------------------------------------------------------------------+

                
 
Agent86:
Here is some of my progress, for a selectible time and/or time range

Incomplete and crude but at least I do understand all the posts now thanks a bunch


And yet, Time_Select is incorrect.
 
Yep thanks I see it
I thought about it right after I posted it but left to eat dinner lol

Time_Select = bod + extHour*3600 + extMinutes*60,
I know I can eventually figure out how to simply use an actual user input for 7:15 or some such time but still nice to see the results I was looking for.

One function understanding at a time I think I need to work on, I probably crammed too much information in learning syntax and didn't work through each and every dictionary function and topic good enough to really make things easier for me.

Anyhow after all this time I finally have a handle on time including managing my own to be able to learn mql better.

Thanks again all
 
Why can't I just use this for selecting a time, did I make this more complicated then it was ?

datetime var1=StrToTime("7:15");

if(Time[1] == var1)
{
}
Anything wrong with this ?
 
Agent86:
Yep thanks I see it
I thought about it right after I posted it but left to eat dinner lol

:-)
 
Anyone see any problems with using StrToTime in this way for time and straddle selections ?

Please advise thanks

//+------------------------------------------------------------------+
//|                                      straddle_with_timerange.mq4 |
//|                           Agent86's Candle Straddle with timer   |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Agent86"


//---- input parameters
extern double    TakeProfit=20.0;
extern double    Lots=0.1;
extern double    StopLoss=10.0;
extern int       MagicNumber=1586;

extern string    Straddle_Candle="7:15"; //select your straddle candle
extern string    StartTime="7:15"; //select your start time range
extern string    EndTime="17:00"; //select your end time range


//++++ These are adjusted for 5 digit brokers.

int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)

    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   if (Digits == 5 || Digits == 3)
   {    // Adjust for five (5) digit brokers.
      pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
   } 
   else 
    {    
      pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; 
    }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
     
   
    
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
   
    
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

datetime Candle_Select = StrToTime(Straddle_Candle),
         Start_Time = StrToTime(StartTime),
         End_Time = StrToTime(EndTime);
         
if (Time[1] == Candle_Select)
   {
   double Low_Mark = Low[1] - 20*pips2dbl,
          High_Mark = High[1] + 20*pips2dbl;
   Print (Low[1], " = Low ", Low_Mark," = Low_Mark"); 
   Print (TimeToStr(Time[1])," Low =", Low[1], " High =", High[1]);
   }
      
          
   return(0);
  }    

//+------------------------------------------------------------------+

                
Reason: