Download MetaTrader 5
To add comments, please log in or register
Speed up MQL5 Cloud Network. Install Strategy Tester Agent!
kemalturgay
265
kemalturgay 2014.10.03 18:47 

I've just started to study MQL4 and I would like to ask some questions about event handlers in EAs.


1. Is OnInit the default handler for any EA ... that is, we should place all the codes in this event handler?

2. If we want to make trades on tick base, should we use OnTick event in place of OnInit?

3. What is the differences between OnInit and OnStart?


Thanks a lot.

kemalturgay
265
kemalturgay 2014.10.03 19:02  
Or, maybe ... should OnTick be used as a general code wrapper in an EA?
JC
1389
JC 2014.10.03 20:10  
kemalturgay:
Or, maybe ... should OnTick be used as a general code wrapper in an EA?

Yes, that.

In an EA, OnInit() is called once when the EA is loaded and OnDeinit() is called once when the EA is unloaded. OnTick() is called repeatedly whenever there is a new tick for the chart symbol.

If you only want to do something once per bar, or only when a new trade action happens, then you implement that yourself inside OnTick(). For example, in OnTick() you keep a record of the current bar start-time - Time[0] - and only do something when that changes. (A long time ago, I drew an analogy between this approach and RISC computing, compared to the CISC computing in platforms which have separate events such as OnNewBar() or OnTrade().)

There are limits to the amount of time which an EA is allowed to spend in OnInit() or OnDeinit(). The platform will forcibly terminate the EA if it tries to carry out operations which are too lengthy.

A script uses OnStart() rather than OnTick(), because it is called once and then unloaded. A script is allowed to have code for OnInit() and OnDeinit(), but there is very little point because this code could equally well be put in OnStart().

kemalturgay
265
kemalturgay 2014.10.03 21:41  
jjc:

Yes, that.

In an EA, OnInit() is called once when the EA is loaded and OnDeinit() is called once when the EA is unloaded. OnTick() is called repeatedly whenever there is a new tick for the chart symbol.

If you only want to do something once per bar, or only when a new trade action happens, then you implement that yourself inside OnTick(). For example, in OnTick() you keep a record of the current bar start-time - Time[0] - and only do something when that changes. (A long time ago, I drew an analogy between this approach and RISC computing, compared to the CISC computing in platforms which have separate events such as OnNewBar() or OnTrade().)

There are limits to the amount of time which an EA is allowed to spend in OnInit() or OnDeinit(). The platform will forcibly terminate the EA if it tries to carry out operations which are too lengthy.

A script uses OnStart() rather than OnTick(), because it is called once and then unloaded. A script is allowed to have code for OnInit() and OnDeinit(), but there is very little point because this code could equally well be put in OnStart().

Thanks a lot jjc.
whroeder1
13596
whroeder1 2014.10.04 01:04  
kemalturgay:. What is the differences between OnInit and OnStart?
Read the documentation. Event Handling Functions - MQL4 Documentation
kemalturgay
265
kemalturgay 2014.10.05 12:22  
kemalturgay:
Thanks a lot jjc.

I can not open a new topic anymore  ... I'm getting the following warning.

Unfortunately, your message cannot be added due to any of the following reasons:
1) the entry has already existed
2) there have been limits for non-approved users
3) the message interval has not reached 30 sec.


What should I do?

I think that I'm approved user and the last condition is not valid for me now.

What does "the entry has already existed" mean exactly?

/
To add comments, please log in or register