Thanks DxdCn. Help for beginners checking your code

 
Firstly thank you to DxdCn for his help.
It took a while to work out where and how to use the log file, however I now have it.

I am a real novice and have been running around in the dark for quite a while.
If your also a real beginner then the following may assist.

The problem is I am never sure what my code is doing, when it doesn't give the results I expect.
When learning any code you normally have the assistance of an IDE (intergrated development environment). unfortunately MQL4 doesn't have one.
However there is a crude partial IDE that can be of tremendous assistance, in understanding at least what values were, at any time during the code execution.

You can study a LOG file that is created when your Indicator is attached to the METATRADER Chart Window, or Separate Window.

(1) Open a Chart of your choice in MetaTrader4
(2) On the top tool bar go VIEW then TERMINAL Then on the tabs along the bottom of TERMINAL Click EXPERTS.
This will show the LOG FILE


(3) Open Metaquoted language editor (MQL4)
(4) Open an Indicator of your choice
(5) Write a line of code directly under the code you are investigating (Print(pos, " " , Variable name)
(6) Re-Compile your code
(7) This will print to the EXPERT LOG WINDOW in MetaTrader4 the
(a) The Position of bar being evaluated at the time and
(b) The value of variable for that bar,


e.g. my variable name is dResult
Bar dResult
0 1.3318
1 1.3299
2 1.3305
3 1.3301
4 1.3309

(8) If it doesn't write or add to the log file try right clicking on the MetaTrader4 chart and REFRESHING, then Re-Compile again.

By including many parameters separated by "," you can check several related values at the same time e.g.
(Print(pos, " " , Variable1, Variable2, Variable3, Variable4, etc, etc)

To those in the Know, you probably chuckly at such a basic level. for those like me it is a very important Tool in the debugging, and learning process. To the beginner basic elements are not always obvious.
It still does not explain the complexities of BUFFERS etc etc . However its a step in the right direction.

Again Thank you DxdCn

PS. Forgive me if I've erred or left anything out. If I have check with the experts

Regards
peter_zyn

 
 
You are welcome !
Print function is basic debug method for MQL4.
MQL4 is not a easy language if one does not have any C language foundation.
Reason: