Elementary Inquiry on Codes - page 2

 
Hi.

I would like to ask the following:

1. Init - does something that you want the EA to do as it is loaded in the chart. If that is so, why does this not prompt the Hello world upon load of the EA?
int OnInit()
  {
   return(INIT_SUCCEEDED);
   Print("Hello World");   
  }

- Why do the following errors show?

// This:
void OnInit();
//or
void Init();
//gives the error message: '{' - function definition unexpected


// while this:
void OnInit()
//or
void Init()
//gives the error message: 'return' - 'void' function returns a value

- Is the Init/OnInit part of the code optional?

- Is Init same as OnInit? If no, how are they different? I read that Init is for MQL4 and OnInit is for MQL5. Is there any difference other than the syntax?

2. Deinit - shows an error message why the EA failed. I was unable to test it but is this correct?

- Is Deinit same as OnDeinit? as stated above.

- I read that void classes do not return any value. But why does void Deinit (); return the reason for deinitialization?

3. Start - It is said that this is for scripts and not EA. https://docs.mql4.com/runtime/event_fire#start however, it works fine in my EA. Furthermore, a certain EA generator website uses this Start function as a default command which encompasses all OpenBuy, OpenSell, etc orders. Can anyone clarify this?

4. OnTick - It seems to work fine, in the same precise way Start works. But sometimes, Start works but OnTick fails. How can that be? How are the 2 different? The only distinction between them is as said by the abovementioned site, but in my test case it does not seem to be the case.

5. Print - when must the "void" class be included in the code, as the mql4 guide has mentioned in the examples? My experience shows that sometimes it requires the void portion. At times it does not. Is this discrepancy due to the Print() function or the void class? If so, what might that be?

These will be all for now.

I thank you in advance for your patience. Your guidance is very much appreciated. :)

Client Terminal Events - MQL4 programs - MQL4 Reference
Client Terminal Events - MQL4 programs - MQL4 Reference
  • docs.mql4.com
Immediately after the client terminal loads a program (an Expert Advisor or custom indicator) and starts the process of initialization of global variables, the Init event will be sent, which will be processed by OnInit() event handler, if there is such. This event is also generated after a financial instrument and/or chart timeframe is changed...
 
nicholishen:

Hahaha... how did this go unnoticed? I seriously think that the whroeder1 account is run by a bot and occasionally checked by a human. 

It's been established that there is a bug in the round function for half-rounding. Instead of round you should use

  1. You can't be serious.
  2. It was established in that other thread, that your values resulted in a value of x.499999 which MathRound correctly rounded down and NormalizedDouble (incorrectly) did not.
 
Ibex Thales:
Hi.

I would like to ask the following:

1. Init - does something that you want the EA to do as it is loaded in the chart. If that is so, why does this not prompt the Hello world upon load of the EA?

- Why do the following errors show?

- Is the Init/OnInit part of the code optional?

- Is Init same as OnInit? If no, how are they different? I read that Init is for MQL4 and OnInit is for MQL5. Is there any difference other than the syntax?

2. Deinit - shows an error message why the EA failed. I was unable to test it but is this correct?

- Is Deinit same as OnDeinit? as stated above.

- I read that void classes do not return any value. But why does void Deinit (); return the reason for deinitialization?

3. Start - It is said that this is for scripts and not EA. https://docs.mql4.com/runtime/event_fire#start however, it works fine in my EA. Furthermore, a certain EA generator website uses this Start function as a default command which encompasses all OpenBuy, OpenSell, etc orders. Can anyone clarify this?

4. OnTick - It seems to work fine, in the same precise way Start works. But sometimes, Start works but OnTick fails. How can that be? How are the 2 different? The only distinction between them is as said by the abovementioned site, but in my test case it does not seem to be the case.

5. Print - when must the "void" class be included in the code, as the mql4 guide has mentioned in the examples? My experience shows that sometimes it requires the void portion. At times it does not. Is this discrepancy due to the Print() function or the void class? If so, what might that be?

These will be all for now.

I thank you in advance for your patience. Your guidance is very much appreciated. :)

Up. :)

 
nicholishen:

Hahaha... how did this go unnoticed? I seriously think that the whroeder1 account is run by a bot and occasionally checked by a human.

Please stop that behaviour.

Forum on trading, automated trading systems and testing trading strategies

General rules and best pratices of the Forum.

Alain Verleyen, 2018.03.11 19:44

Forum rules, enforced by moderators :

  1. Please be polite when communicating on this website. Refrain from statements that may offend or insult other users.
  2. Negative discussions of any banking, brokerage and other financial institutions are not allowed.
  3. Any discussions about personal relations between the community members are not tolerated.
  4. Coarse language, advertising messages, spamming and flooding are forbidden.
  5. Repeated violation of the Rules, ignoring moderator's remarks and open disrespect for the website Administration will lead to an account termination.
  6. The website Administration may implement any changes to the Rules it deems necessary.

Your statement is a direct attack on WHRoeder and is not acceptable.I hope you will agree we have to stop repeating the errors of the past.

 

nicholishen:

It's been established that there is a bug in the round function for half-rounding. Instead of round you should use 

whroeder1:
  1. ...
  2. It was established in that other thread, that your values resulted in a value of x.499999 which MathRound correctly rounded down and NormalizedDouble (incorrectly) did not.

Actually what is established is that MathRound() and NormalizeDouble() are rounding in a different way. Nothing more. Half rounding up is the common method, but it's not the only one, and it's not mandatory.

Saying now that one should always use NormalizeDouble() while rounding (normalizing to tick) a price, is not better than saying that NormalizeDouble() usage is always wrong.

Reason: