A newbie question

 

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.

 
Or, maybe ... should OnTick be used as a general code wrapper in an EA?
 
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().

 
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.
 
kemalturgay:. What is the differences between OnInit and OnStart?
Read the documentation. Event Handling Functions - MQL4 Documentation
 
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?

Reason: