Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Introduction to the use of

MQL
Introduction of use of MQL
Building blocks

Alerting Regular
Data fetching Data processing
Reporting

Order Trading
Data analysis Charting strategies
management

Database Account VPS


Backtesting
Management management setup
Agenda
• Example of simple EA
• Types of variables
• Scope of variables
• Getting instrument data
• Account information
• Datetime function
• For loop
• If
• Function
• Order functions
• Indicators
Overview of expert advisor (Sample)
Define input parameter

Perform task
on each tick
Define local variables

Define indicators

Check enter condition


and perform order placement
Types of variables
• int
• double
• string
• bool
• color
• Datetime
Scope of variable
• Local variable
• It is declared inside of a function. Local variables are allocated in memory
when the function is first run. Once the function has exited the variable is
cleared from memory
• Global variable
• A global variable is one that is declared outside of any function. Global
variables are defined at the top of the program and the scope of the global
variable is the entire program.
• Static variable
• A static variable is a local variable that remains in memory even when the
program has exited the variable’s scope..
Example-Scope of variables
Global variable

Local variable

Static variable
Example-Get Instrument data
Market information
• MarketInfo(string
symbol,int type)
• Type includes:
• MODE_BID
• MODE_ASK
• MODE_SPREAD
• MODE_POINT
• MODE_DIGITS
• MODE_LOTSIZE
Date time information
• Day()
• Second()
• Minute()
• Hour()
• Year()
• Month()
• TimeLocal()
• TimeCurrent()
Get account information
• AccountCompany()
• AccountLeverage()
• AccountBalance()
• AccountEquity()
• AccountFreeMargin()
• AccountMargin()
• AccountProfit()
For loop and if statement
Use of functions
Order function

• OrderSend()
• OrderModify()
• OrderClose()
• OrderSelect()
• OrderTotal()
Example-Order functions
for (int i=OrdersTotal()-1;i>=0;i--)
{

if ((OrderSelect(i,SELECT_BY_POS))&& (OrderMagicNumber()==MAGIC))
{
int myTkt=OrderTicket();
double myLots=OrderLots();
int myType=OrderType();
string mySymbol=OrderSymbol();
double myBid=MarketInfo(NULL,MODE_BID);
// Close order if OrderType equals OP_BUY
}

}
Home work First_Long

Time frame: M5
Instructment: GBPUSD
First_long
Open_Order_long_1
-First enter long condition
-Three consecutive green bars
-And other conditions (To be revised) First_Long
&& Next_Long
Next_Long N
-Enter long condition once First_long condition is true Y
-If current profit-last profit>=20 then enter_long (x2 lots)
Profit taget (e.g. 200) Open_Order_long_2
Profit loss (e.g. -100)

Calculate profit

Order_Close Y Profit target N


Or Profit loss
Home work-phase 1 N
First_Long

Time frame: M5
Instructment: GBPUSD Y

First_long
Open_Order_long_1
-First enter long condition
-Three consecutive green bars
-And other conditions (To be revised) First_Long
&& Next_Long
Next_Long N
-Enter long condition once First_long condition is true Y
-If current profit-last profit>=20 then enter_long (x2 lots)
Profit taget (e.g. 200) Open_Order_long_2
Profit loss (e.g. -100)

Calculate profit

Order_Close Profit target N


Y Or Profit loss
Strategy_1 First_Long

First_long
-First enter long condition
Fall_back
Open_Order_long_1
-When it is in high position (Based on the highest order
price of the buy orders) and it falls back beyond certain
points or percentage, open order with Nx lot size
(configurable, e.g. N=2) First_long N First_Long
Next_Long && Fall_Back && Next_Long
N
-Enter long condition once First_long condition is true Y Y
Profit taget
Stopploss Open_Order_long_2
Open_Order_Short

Calculate profit
Calculate stop loss value

Order_Close Y Profit target N


Or Stoploss

You might also like