How do I create 60 seconds' cycles?

 

Hi all,

first of all, thanks to anyone reading this that replied to my previous topic.


This time I'm struggling with time management: I need to check (every 60 seconds) if the trade has reached TP or SL.


For this I'm using the TimeLocal(); function: each tick I store the new value in a variable (carrenttl); then (inside the while op) saving the TimeLocal in a different variable (taimlocal). And I'm trying to run the loop as long as the difference between the second variable and the first one is smaller than 60 (as datetime variables like the two mentioned above are equivalent to the second elapsed from 1/01/1970).


It compiles without errors but when I look at the log it does everything in about 7 seconds, as opposed to the 60 that I'm expecting.


Would you have any suggestion on why this is not working or if there's a way that this can be done more efficiently?


Thank you for your time

E.

//+------------------------------------------------------------------+
//|                                               cheduecoglioni.mq5 |
//|                                                   Gianni Esperti |
//|                                  https://www.gianniesperti.come? |
//+------------------------------------------------------------------+
#property copyright "Gianni Esperti"
#property link      "https://www.gianniesperti.come?"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

#include <Trade\Trade.mqh>
CTrade trade;

uint s;
int r;
datetime taimlocal;
datetime carrenttl;

int OnInit()
   {
   
      MathSrand( GetTickCount() );
      
   s = GetTickCount();
   r = MathRand();

   double Ask = NormalizeDouble ( SymbolInfoDouble (_Symbol, SYMBOL_ASK), _Digits );
   
      if (r <= 16383)
            {

               Print(r, " bitches in my Lex");
               trade.Buy (0.01, NULL, Ask, 0, ( Ask + 100 * _Point ), NULL);
               taimlocal = TimeLocal();
               
            }
            else
            {
            
               Print(r, " of my beats in yo stereo");
               trade.Sell (0.01, NULL, Ask, 0, ( Ask - 100 * _Point ), NULL);
               taimlocal = TimeLocal();
               
            }
   
   
    
   return (INIT_SUCCEEDED);
   }

void OnTick()
   {  
    
    carrenttl = TimeLocal ();
    
      do
         {
            
            Print ("Still not 60 sec?");
            
         }
      while ( (carrenttl - taimlocal) < 60 );


   }
 

Set the timer for 1 minute:

EventSetTimer(60);

Run your check in OnTimer() 

void OnTimer()
  {
   // do something every 60 seconds
  }
 
honest_knave:

Set the timer for 1 minute:

Run your check in OnTimer() 


Thank you knave.

I was sure there had to be something simpler than what I was trying.

Now I just need to find out how to check if the trade exceeds TP or SL.


Thank you again

E.

Reason: