Time elapsed since EA began

 

I need to know the time when my EA started. I looked at the sleep function but is there any way?

 
cryptex:

I need to know the time when my EA started. I looked at the sleep function but is there any way?

Add a Print() to the OnInit()/init() function . . .
 
cryptex:

I need to know the time when my EA started. I looked at the sleep function but is there any way?

It's already in the log, see Experts tab.

2014.03.05 18:20:00.807 Moving Average GBPUSD,M30: initialized
2014.03.05 18:20:00.807 Moving Average GBPUSD,M30 inputs: Lots=0.1; MaximumRisk=0.02; DecreaseFactor=3.0; MovingPeriod=12; MovingShift=6;

Moving Average is EA name.
 
cryptex: I need to know the time when my EA started. I looked at the sleep function but is there any way?
or remember it
datetime EAstarted;
int OnInit(){ EAstarted = TimeCurrent(); ...
 
RaptorUK:
Add a Print() to the OnInit()/init() function . . .


brilliant RaptorUK you are a genius. You have an eye for details. hey and i remember reading somewhere that mql can return the time elapsed since i think january 1970 or something? basically I want to sync my EA with in multiples of 30 seconds since midnight. what would be the most efficient way? and a last Q, what is the format of the time stored in mql. I intend on sending some parameters to MATLAB every 30 seconds. Would i better off using sleep function or the eventsettimer? Asked too many Qs :D

 
cryptex:


brilliant RaptorUK you are a genius. You have an eye for details. hey and i remember reading somewhere that mql can return the time elapsed since i think january 1970 or something? basically I want to sync my EA with in multiples of 30 seconds since midnight. what would be the most efficient way? and a last Q, what is the format of the time stored in mql. I intend on sending some parameters to MATLAB every 30 seconds. Would i better off using sleep function or the eventsettimer? Asked too many Qs :D

A datetime type is the number of seconds elapsed since midnight 1st Jan 1970. There is a function to convert this into a man readable date and time . . .

To send data every 30 seconds don't use Sleep() use OnTimer() also bear in mind that if you haven't had a tick in the last 30 seconds Bid, Ask, Volume, Server time, etc. won't have changed.
 
RaptorUK:
A datetime type is the number of seconds elapsed since midnight 1st Jan 1970. There is a function to convert this into a man readable date and time . . .

To send data every 30 seconds don't use Sleep() use OnTimer() also bear in mind that if you haven't had a tick in the last 30 seconds Bid, Ask, Volume, Server time, etc. won't have changed.

thanks
So basically it updates upon the arrival of a tick.

hey could please elaborate a bit on the OnTimer() and how i go about using eventsettimer or a small example? couldn't find much on it :(

 
cryptex:

thanks
So basically it updates upon the arrival of a tick.

hey could please elaborate a bit on the OnTimer() and how i go about using eventsettimer or a small example? couldn't find much on it :(

Yep, the server time is updated on a tick, you can get it using TimeCurrent()


I've not used OnTimer() yet, but from the documentation it seems that you set the time using EventSetTimer() called from OnInit()

 
cryptex:


So basically it updates upon the arrival of a tick.


to activate the EventSetTimer() that's been set in OnInit u need a tick, but once the EventSetTimer() is active tick isn't needed for this to work (it's been executed even there is no connection to the server)

 
cryptex:


So basically it updates upon the arrival of a tick.

to activate the EventSetTimer() that's been set in OnInit u need a tick,

but once the EventSetTimer() is active tick isn't needed for this to work (it's been executed even there is no connection to the server)


cryptex:

hey could please elaborate a bit on the OnTimer() and how i go about using eventsettimer or a small example? couldn't find much on it :(

#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(30);
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   Alert("past 30 Seconds");
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   
  }
//+------------------------------------------------------------------+
 
qjol:

to activate the EventSetTimer() that's been set in OnInit u need a tick,

but once the EventSetTimer() is active tick isn't needed for this to work (it's been executed even there is no connection to the server)



thanks a lot :)