1 //+------------------------------------------------------------------+ 2 //| chuale.mq4 | 3 //| Copyright 2014, MetaQuotes Software Corp. | 4 //| https://www.mql5.com | 5 //+------------------------------------------------------------------+ 6 #property copyright "Copyright 2014, MetaQuotes Software Corp." 7 #property link "http://www.abc.com" 8 #property version "1.00" 9 #property strict 10 11 //+------------------------------------------------------------------+ 12 //| Expert initialization function | 13 //+------------------------------------------------------------------+ 14 int init() 15 { 16 17 //--- 18 //--- 19 return(0); 20 } 21 //+------------------------------------------------------------------+ 22 //| Expert deinitialization function | 23 //+------------------------------------------------------------------+ 24 int deinit() 25 { 26 //--- 27 28 return(0); 29 } 30 //+------------------------------------------------------------------+ 31 //| Expert tick function | 32 //+------------------------------------------------------------------+ 33 int start() 34 { 35 Total=OrdersTotal(); 36 37 if(A<B) 38 { 39 ...... 40 ...... 41 return(0); 42 } 43 44 if (A<C) 45 { 46 ......... 47 return(0); 48 } 49 return(0); 50 }so when the ea attach to chart, it execute line 14 to line19, then line 33 to line 50. My question is when it encounter line 19, line 41, line 47 and line 49, what will happen? For example, if it encounter return(0) at line 41, will it go back to line 33 or it continue with line 42, 43, 44 etc?
When it reaches line 19 it returns from the init() function to the caller which is the terminal. when it reaches any return statement in start, it returns to the caller which is the terminal.
int start(){ myFunction(); Print("returned from myFunction"); } void myFunction(){ Print("in myFunction"); // return is optional for void functions, the closing brace is a return. } // output: // in myFunction // returned from myFunction
Hi ,
I refer to mql4 manual and it did not explain clearly about return(0). Does it mean that the return(0) will pass any return value to the terminal and continue with subsequent line of coding?
Hi ,
I refer to mql4 manual and it did not explain clearly about return(0). Does it mean that the return(0) will pass any return value to the terminal and continue with subsequent line of coding?
The statement stops the current function and continues by the next statement in the caller function. In this case it is inside an event handler (start()), so it returns to the event dispatcher, which you have no access to.
chuale: and continue with subsequent line of coding?
|
|
//+------------------------------------------------------------------+ //| mql4 example.mq4 | //| Copyright 2014, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2014, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int start() { myFunction(); Print("returned from myFunction"); } void myFunction() { Print("in myFunction"); // return is optional for void functions, the closing brace is a return. } // output: // in myFunction // returned from myFunctionI compile it and it has error
chuale: I compile it and it has error
|
|
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
What is the function of return(0)? When encounter, does the program go to start() or continue downward?
Regards