Professional Documents
Culture Documents
Use of MQL
Use of MQL
MQL
Introduction of use of MQL
Building blocks
Alerting Regular
Data fetching Data processing
Reporting
Order Trading
Data analysis Charting strategies
management
Perform task
on each tick
Define local variables
Define indicators
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
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
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