MQL4 - automated forex trading   /  

Forum

Login | Register | Language: ru cn en
How to Use MQL5 Constructions? Check the Documentation!

'OnTick' and OnTimer

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
14
BHC 2014.02.15 23:03
 

I would like to run my EA at a predefined interval irrespective of when/ if the EA gets any new ticks from the server. I am trying something like this

extern int     _tick = 1;

//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
static int _tick_time;

void start()
   {
      
      if(TimeCurrent()<_tick_time)        { Sleep(_tick_time-TimeCurrent());                         }
      else if(TimeCurrent()>=_tick_time)  { _tick_time=TimeCurrent()+(60*_tick); MyTimerFunction();  }
   }

void MyTimerFunction()
   {
      //My main code...
   }

My question is, can it be possible to have the start (or 'OnTick') function run in parallel with my main code.

With this code can I be sure a new tick will not stop the running of my other code?

Secrets of MetaTrader 4 Client Terminal: File Library in MetaEditor
When creating custom programs, code editor is of great importance. The more functions are available in the editor, the faster and more convenient is creation of the program. Many programs are created on basis of an already existing code. Do you use an indicator or a script that does not fully suit your purposes? Download the code of this program from our website and customize it for yourselves.
avatar
3097
qjol 2014.02.15 23:23 #
 

y not use

struct MqlTick
  {
   datetime     time;          // Time of the last prices update
   double       bid;           // Current Bid price
   double       ask;           // Current Ask price
   double       last;          // Price of the last deal (Last)
   ulong        volume;        // Volume for the current Last price
  };
avatar
Moderator
2704
angevoyageur 2014.02.16 00:26 #
 
BHC:

I would like to run my EA at a predefined interval irrespective of when/ if the EA gets any new ticks from the server. I am trying something like this

My question is, can it be possible to have the start (or 'OnTick') function run in parallel with my main code.

With this code can I be sure a new tick will not stop the running of my other code?

You can now use the OnTimer() event handler, with EventSetTimer(), see Mql4 reference by pressing F1 in MetaEditor.

avatar
14
BHC 2014.02.18 18:34 #
 
angevoyageur:
You can now use the OnTimer() event handler, with EventSetTimer(), see Mql4 reference by pressing F1 in MetaEditor.


OnTimer is not working...

Am using OnTick with the above code… hope this is resolved soon.

avatar
Moderator
2704
angevoyageur 2014.02.18 19:08 #
 
BHC:


OnTimer is not working...

Am using OnTick with the above code… hope this is resolved soon.

OnTimer() is working well (build 610), what you have tried ?
avatar
9777
WHRoeder 2014.02.18 19:18 #
 
BHC: OnTimer is not working...
  1. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. Did you turn on the timer? MQL4 Documentation
avatar
14
BHC 2014.02.18 20:43 #
 
I set the timer like in mql5
avatar
14
BHC 2014.02.18 20:51 #
 
My EA with only the on timer was placing no trades. When I placed 'Print' statements in the timer function nothing was appearing in terminal log. Only OnTick was printing.
avatar
Moderator
2704
angevoyageur 2014.02.20 18:44 #
 
BHC:
My EA with only the on timer was placing no trades. When I placed 'Print' statements in the timer function nothing was appearing in terminal log. Only OnTick was printing.
Show your code if you need help.
avatar
1
stefanbanev 2014.03.18 23:26 #
 
angevoyageur:
Show your code if you need help.


I have the same problem ( Version: 4.00 Build 610 (14 Feb 2014), the test code is below:

define N_minutes 5

int OnInit()
{

EventSetTimer(60*N_minutes ) ;

Print("Error GetLastError() = ", GetLastError() ) ;

return(INIT_SUCCEEDED);
}

void OnTimer()
{

Print(" !!! Timer_in !!!") ;

}

I'm working with MB Trading FX, may be this new functionality is vendor dependent(?)

Thanks


avatar
Moderator
2704
angevoyageur 2014.03.19 00:29 #
 

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

Back to topics list   | 1 2  

To add comments, please log in or register