⚡ Introduction of MQL Script and use of Comments in MQL

Introduction of MQL Script and use of Comments in MQL ⚡

Introduction of MQL Script and use of Comments in MQL KHOPADI
Lesson 02 - Introduction of MQL Script and use of Comments in MQL



When you want to learn any new programming language. you should probably start from the easiest point. so that you can the fundamentals of this computer programming language.

In the case of MQL, You must start by learning Script Development.

What is MQL Script?

MQL Script is the program developed for a single execution, which means Script runs only once.

Then the question was raised in your mind, "What is the problem with Single Time Execution?".

The answer is, "There is no problem with Single Time Execution.". whereas you are learning this MQL Computer Programming language for Forex Trading Automation, and the price in the chart change with each tick of Watch. then ???

It's Okay !!!
The Developers of MQL have made a provision of Recursive Program Executors which are run on each tick change of price, called Expert Advisors. we will discuss Expert Advisors in later Tutorials.

Reasons for Learning MQL Scripts, First

You must start learning MQL Script first because of the following reasons:-
  • MQL Script is easy to create.
  • You can learn MQL fundamentals easily.
  • You can see the output of logic instantly.
  • Built Confidence, that you can code your trade.

In the previous Tutorial of MQL:-  Basic "Hello World Program" Execution

We have created the simplest MQL Script which is printing "Hello World".

void OnStart()
  {

      Alert("Hello World 1");
      
      Print("Hello World 2");
        
      Comment("Hello World 3");
   
  }

MQL Script has two major Sections:- (* Author Opinion for easy learning)
  • Inside the "OnStart" function
  • Outside the "OnStart" function
Tip:- you will find a more depth tutorial on "Function", at that point you can assume that It is part of the code which can perform certain work. this can be denoted by " ( ) ", pair of open and close parenthesis.

OnStart(): This is a pre-defined function, which is the starting point of MQL Script or in other words, Execution of MQL Script is started from here.

Inside the "OnStart" function

At the beginner level, you should code your MQL Script inside the OnStart() Function. You can practice all of the basic MQL fundamentals inside these functions like:-
  • Comments
  • Variables
  • If-Else / Switch
  • For / While Loop
  • Array
  • Use of Technical Indicators, etc.

Thus, I create all of the beginner MQL Tutorials inside the OnStart() Function.

Outside the "OnStart" Function

Once you practice your basics, then you should come outside the OnStart() Function. I create the following MQL Tutorials outside the OnStart() Function.

  • User-Defined Functions (With return value and without return value)
  • Global Variable Scope and Extern Variable Input.

Now, come inside the OnStart() Function with me. 😀

Comment

The comment is non-executable code. A comment is not converted to Machine Code when the compiler compiles the "Source Code".

Source-Code: Computer Programming original human-readable code is called as Source-Code.

Machine-Code: Combination of 0's and 1's, which is readable only by computer.

Compiler: The Software created by the original developer of Programming Language, which is used to convert the Source Code into Machine Language code. because computers can only understand Machine Level Code.

Means, Comment is the code which is used for:-

  • Taking Notes for future remembering.
  • Easy Debugging of Code in Future.
  • Makes easy the reading of Program Logic.
  • Code Documentation.

How to write a Comment in MQL4?

Comment can be write in Two ways as per requirement:-

Single Line Comment  

Single Line Comment is used for Quick Note, like describing the use of a Variable or a Function.

Multi-Line Comment 

Multi-Line Comment is used for Details Notation, like Logic of Trading Algorithm, etc.
See the Example of Comment as below:-

Comments in MQL4 KHOPADI


How to write a Single Line Comment?

Single line comment starts with "//" Two Forward Slashes.
The compiler ignores all of the code written after "//". This is the single-line comment.

You can write only one line of a comment using a Single line comment.

void OnStart()
  {

      // This is single line comment - Hello World example - Boom
      
      Alert("Hello World 1");       
      
  }

How to write Multi-Line Comment?

Multi-Line comment has both of the ends:-
  • Starting of Multiline Comment: written with "/*" [One Forward Slash + One Star Symbol]
  • Ending of Multiline Comment: written with "*/" [One Star Symbol + One Forward Slash]
You can write any number of lines in Comment using Multi-Line Comment.

void OnStart()
  {
      /* This is multi line comment 
         - Hello World example 
         - Boom
      */
            
      Alert("Hello World 1");       
      
  }

#Forex #Trading #MQL #Best #Knowledge #KHOPADI #latest

Summary

MQL script is used for writing single-time executable code. the beginner in MQL Programming must start from here because it is quite easy to learn. You can write any notes for future use in between the MQL Script as a comment. which is non-executable code either a single line or multiple lines.