where is the entry point of program? from newbie

 

Hi,guys. It's first time posting the theme. If I broke the rule, plz tell me. I am a C programmer, and I don't know where the entry point is(it's main() in C). 

For example:


//External,variables

extern double LotSize = 0.1;

...

...

// Global variables

int BuyTicket;

int SellTicket;

...

int (UseSlippage; // What's this line? no right bracket with a semicolon?

// int function

int init()

{

UsePoint=PipPoint(Symbol());

UseSlippage=GetSlippage(Symbol(),Slippage);

}

// Start function

int start()

{

...... //Omitted

return(0)

}


is the start() entry point??

btw, there is no need to define function prototype, right?

 
First time when the EA is loaded it runs Init().. After then it goes to start
 
Shehbaz Nawaz:
First time when the EA is loaded it runs Init().. After then it goes to start


thx, bro. So when EA is loaded second time after that it starts from int start(), right?

btw, what's difference between external variable and global variable? In C, there is no difference if it's defined outside the main() but when it comes to multiple .cpp file. Does It work in the same way in MQL4?

 
Lin Andy:


thx, bro. So when EA is loaded second time after that it starts from int start(), right?


OnInit()  = new

init() = old

OnInit() will run as soon as the terminal loads the EA or Indicator. It will also run if you change the chart timeframe or symbol, or if you recompile the source, or if you change an input parameter or if the account is changed (EAs only).


OnTick() and OnCalculate() run each tick.


Lin Andy:


btw, what's difference between external variable and global variable? In C, there is no difference if it's defined outside the main() but when it comes to multiple .cpp file. Does It work in the same way in MQL4?


extern is different between MQL4 and MQL5

Variables defined with extern or input will appear as an input setting for the user (not extern for MQL5).

Have a read through the language basics in the documentation and that should help with the differences.

MQL4 Language Basics - https://docs.mql4.com/basis

MQL5 Language Basics - https://www.mql5.com/en/docs/basis

Client Terminal Events: https://docs.mql4.com/runtime/event_fire


Also, please note that the MQL4 language was overhauled from Build 600. Many of the online learning resources use the old style MQL4. They haven't been updated to reflect the changes.

Now, MQL4 and MQL5 are very similar with some notable differences, like order handling.

Language Basics - MQL4 Reference
Language Basics - MQL4 Reference
  • docs.mql4.com
Language Basics - MQL4 Reference