
Hầu hết các hệ thống giao dịch đều sử dụng các chỉ báo để xác định tín hiệu giao dịch. Metatrader bao gồm hơn 20 chỉ báo thường được sử dụng, bao gồm đường trung bình động, MACD, RSI và chỉ báo ngẫu nhiên. MQL có chức năng chỉ báo tồn kho tích hợp. Bạn cũng có thể sử dụng các chỉ báo tùy chỉnh trong Expert Advisor của mình. Tìm hiểu cách lập trình Expert Advisor để giao dịch với các chỉ báo xu hướng phổ biến nhất trong bài viết EA Chỉ báo xu hướng MQL4 này.
Chỉ báo xu hướng
Đường trung bình động là chỉ báo xu hướng nổi tiếng nhất. Nó cho biết giá tăng hay giảm trong khoảng thời gian chỉ báo. Chúng ta đã biết cách xây dựng các điều kiện để giao nhau với các đường trung bình động. Hãy kiểm tra các điều kiện vào và ra của chiến lược trên các chỉ báo xu hướng khác.
Nếu bạn truy cập bảng điều khiển MT4 và nhấp vào Chèn/Chỉ báo/Xu hướng, bạn sẽ nhận được danh sách các chỉ báo sau:
Chỉ số định hướng trung bình
Dải Bollinger
Chỉ số kênh hàng hóa
Đường trung bình động
Parabol SAR
Độ lệch chuẩn
| Thông số | Chỉ số định hướng trung bình |
|---|---|
//Mua: Đường +DI cao hơn đường -DI , ADX lớn hơn một giá trị nhất định và tăng trưởng (nghĩa là xu hướng mạnh lên) //Bán: -Dòng -D cao hơn đường +DI, ADX lớn hơn hơn một giá trị nhất định Và phát triển (nghĩa là xu hướng mạnh lên) | <
/tr>|
| Extern | extern int adx=0; //Indicator period extern int adu=14; //Period of averaging for index calculation extern double minadx=20; //Minimal threshold value of ADX |
| Indicator Calling | PosDLine =iADX(NULL,adx,adu,PRICE_CLOSE,MODE_PLUSDI,0); NegDLine =iADX(NULL,adx,adu,PRICE_CLOSE,MODE_MINUSDI,0); ADXCurrent =iADX(NULL,adx,adu,PRICE_CLOSE,MODE_MAIN,0); ADXPrevious =iADX(NULL,adx,adu,PRICE_CLOSE,MODE_MAIN,1); |
| BuyCond | if (PosDLine > NegDLine && ADXCurrent >= minadx && ADXCurrent > ADXPrevious) |
| SellCond | if (NegDLine > PosDLine && ADXCurrent >= minadx && ADXCurrent > ADXPrevious) |
| Params | Bollinger Band |
|---|---|
| Intent | //Buy: price crossed lower line upwards (returned to it from below) //Sell: price crossed upper line downwards (returned to it from above) |
| Extern | extern int bandp=0; //Indicator period extern int bandpx=20; //Period of averaging for indicator calculation extern int banddev=2; //Deviation from the main line |
| Indicator Calling | BBLowCurrent=iBands(NULL,bandp, bandpx, banddev,0,PRICE_CLOSE,MODE_LOWER,0); BBLowPrevious=iBands(NULL,bandp, bandpx, banddev,0,PRICE_CLOSE,MODE_LOWER,1); BBUpCurrent=iBands(NULL,bandp, bandpx, banddev,0,PRICE_CLOSE,MODE_UPPER,0); BBUpPrevious=iBands(NULL,bandp, bandpx, banddev,0,PRICE_CLOSE,MODE_UPPER,1); BBCurrentClose = iClose (NULL, 0,0); BBPreviousClose = iClose (NULL, 0,1); |
| BuyCond | if (BBLowPrevious<BBPreviousClose && BBLowCurrent>=BBCurrentClose) |
| SellCond | if (BBUpPrevious>BBPreviousClose && BBUpCurrent<=BBCurrentClose) |
| Commodity Chanel Index | |
|---|---|
| Intent | //Buy: 1. indicator crosses +100 from below upwards. 2. Crossing -100 from below upwards. 3. //Sell: 1. indicator crosses -100 from above downwards. 2. Crossing +100 downwards. 3. |
| Extern | extern int CCp=0; //Indicator period extern int CCpx=14; //Period of averaging for indicator calculation extern int CCLine = 100; |
| Indicator Calling | CCCurrent = iCCI(NULL,CCp,CCpx,PRICE_TYPICAL,0); CCPrevious = iCCI(NULL,CCp,CCpx,PRICE_TYPICAL,1); CCCrossLinePos = CCLine; CCCrossLineNeg =-CCLine; |
| BuyCond | if ((CCPrevious<CCCrossLinePos && CCCurrent >= CCCrossLinePos) || (CCPrevious <=CCCrossLineNeg&& CCCurrent>=CCCrossLineNeg) ) |
| SellCond | if ((CCPrevious>CCCrossLinePos && CCCurrent <= CCCrossLinePos)|| (CCPrevious >=CCCrossLineNeg&& CCCurrent<=CCCrossLineNeg) ) |
| Parabolic Sar | |
|---|---|
| Note | //Buy: Parabolic SAR crosses price downwards //Sell: Parabolic SAR crosses price upwards |
| Extern | extern int sar=0; //Indicator period extern double sarstep=0.02; //Stop level increment extern double sarstop=0.2; //Maximal stop level extern int sar2=0; //Price period |
| Indicator Calling | sarcurrent = iSAR(NULL,sar,sarstep,sarstop,0); sarprevious = iSAR(NULL,sar,sarstep,sarstop,1); closecurrent = iClose(NULL,0,0); closeprevious = iClose(NULL,0,1); |
| BuyCond | if (sarprevious>closeprevious&&sarcurrent<=closecurrent) |
| SellCond | if (sarprevious<closeprevious&&sarcurrent>=closecurrent) |
| MA Rising or Falling | |
|---|---|
| Intent | //Buy: MA grows //Sell: MA falls |
| Extern | extern int maperiod=14; //Period of averaging for indicator calculation extern int mamode = 1; // Type of moving average, 1= Exponential |
| Indicator Calling | macurrent = iMA(NULL,0,maperiod,0,mamode,0); maprevious = iMA(NULL,0,maperiod,0,mamode,1); maprevious2 =iMA(NULL,0,maperiod,0,mamode,2); |
| BuyCond | if(maprevious2 > maprevious && maprevious > macurrent) |
| SellCond | if (maprevious2 < maprevious && maprevious < macurrent) |