Question About seconds in MQL5

 

Hello all,

I wrote a EA code about opening pending orders on a specific time.
The code works as expected, but sometimes I see something strange: it should open one pending order but it opens few of them.

I attach a screenshot from the last execution of today:



As you cann in the same second ( 14:29:58 ) it repeat the event few times. Why? What are those numbers after the seconds? Are them milliseconds?

My goal is open just a SINGLE order for that specific time, not many orders.
Can you help me please?

Thank you for your time :)

Files:
Cattura.PNG  24 kb
 

demox88: Why?

What are those numbers after the seconds? Are them milliseconds?
My goal is open just a SINGLE order for that specific time, not many orders.  Can you help me please?

  1. Your code is broken.
  2. They are milliseconds. A datetime is in seconds.
  3. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    We can't see your broken code.

 
William Roeder #:
  1. Your code is broken.
  2. They are milliseconds. A datetime is in seconds.
  3. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    We can't see your broken code.

Sorry, this is mt first post.

Here is the code:


void prova()
{
   MqlDateTime time;
   TimeToStruct(TimeCurrent(),time);
   int Year         = time.year;        // Year
   int Month        = time.mon;         // Month
   int Day_of_Month = time.day;         // Day
   int Hour         = time.hour;        // Hour
   int Minutes      = time.min;         // Minutes
   int Seconds      = time.sec;         // Seconds
   int Day_of_Week  = time.day_of_week; // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday)
   int Day_of_Year  = time.day_of_year; // Day number of the year (January 1st is assigned the number value of zero)

   if(Day_of_Month == giorno && Month == mese)
   { 
      if(Hour == ora )  
      {
         if(Minutes == minuti)
         {
            //Print("Sono nel minuto giusto");
            if(Seconds == secondi)
            { 


                // here I wrote the pending orders

the issue is that I have multiple pending orders for a specific hour:minute:seconds instead of only one!

Thank you again
 
  1.             if(Seconds == secondi)
                { 
                    // here you create one order per tick; multiple orders in the same second.
    

    To prevent a duplicate, just set secondi to EMPTY after opening.

  2. You must have received the date and time initially. Stop splitting everything up and just use the datetime.

    #define  MAX_DATETIME   D'3000.12.31 23:59:59'
    datetime nextOpen=MAX_DATETIME;
    TYPE someFunct(){ nextOpen = …;
    void prova(){
       if(nextOpen > TimeCurrent() ) return;
       // Pending order
       nextOpen=MAX_DATETIME;
    }
    

  3. There is no need to create pending orders in code.

    1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)

      Don't worry about it unless you're scalping M1 or trading news.

    2. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.

Reason: