Download MetaTrader 5
To add comments, please log in or register
What are the latest MQL5.community news? The Wall section will tell you!
cryptex23
268
cryptex23 2014.03.05 17:04 

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

Simon Gniadkowski
Moderator
17994
Simon Gniadkowski 2014.03.05 17:14  
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 . . .
Alain Verleyen
Moderator
30299
Alain Verleyen 2014.03.05 17:21  
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.
whroeder1
14242
whroeder1 2014.03.05 17:35  
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(); ...
cryptex23
268
cryptex23 2014.03.05 17:46  
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

Simon Gniadkowski
Moderator
17994
Simon Gniadkowski 2014.03.05 18:09  
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.
cryptex23
268
cryptex23 2014.03.05 18:27  
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 :(

Simon Gniadkowski
Moderator
17994
Simon Gniadkowski 2014.03.05 19:52  
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()

qjol
3243
qjol 2014.03.05 20:08  
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)

qjol
3243
qjol 2014.03.05 20:15  
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)
  {
//---
   
  }
//+------------------------------------------------------------------+
cryptex23
268
cryptex23 2014.03.06 04:47  
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 :)
/ /12
To add comments, please log in or register