Thanhanh9/Test / RSI_System_Indicator.mq5
download
raw
6.19 kB
//+------------------------------------------------------------------+
//| RSI + MA Indicator – MT5 |
//| Chuyển đổi từ Pine Script rsi_indicator.pine |
//| |
//| Hiển thị: |
//| • RSI(14) – màu cyan |
//| • MA Slow(200) trên RSI – màu đỏ |
//| • MA Fast(20) trên RSI – màu vàng |
//| • Đường ngưỡng: Buy(55), Sell(45), Mid(50), OB(70), OS(30) |
//| • Vùng nền đỏ/xanh khi RSI >= 70 / <= 30 |
//+------------------------------------------------------------------+
#property copyright "RSI System v2"
#property version "2.00"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots 3
//--- Inputs
input int RSI_Length = 14; // RSI Length
input int MA_Slow_Length = 200; // MA Slow Length
input int MA_Fast_Length = 20; // MA Fast Length
input double BuyThreshold = 55.0; // RSI Buy Threshold
input double SellThreshold = 45.0; // RSI Sell Threshold
//--- Plot: RSI
#property indicator_label1 "RSI"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//--- Plot: MA Slow
#property indicator_label2 "MA Slow"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- Plot: MA Fast
#property indicator_label3 "MA Fast"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrYellow
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- Buffers
double BufRSI[];
double BufMASlow[];
double BufMAFast[];
//--- Indicator handles
int handleRSI;
int handleMASlow;
int handleMAFast;
//--- Levels (tương đương hline trong Pine)
double LevelOB = 70;
double LevelOS = 30;
double LevelMid = 50;
//+------------------------------------------------------------------+
//| Indicator initialization |
//+------------------------------------------------------------------+
int OnInit()
{
//--- Gán buffers
SetIndexBuffer(0, BufRSI, INDICATOR_DATA);
SetIndexBuffer(1, BufMASlow, INDICATOR_DATA);
SetIndexBuffer(2, BufMAFast, INDICATOR_DATA);
//--- Tên ngắn
IndicatorSetString(INDICATOR_SHORTNAME, "RSI+MA");
//--- Levels hiển thị trên sub-window (tương đương hline)
IndicatorSetInteger(INDICATOR_LEVELS, 5);
IndicatorSetDouble (INDICATOR_LEVELVALUE, 0, BuyThreshold);
IndicatorSetDouble (INDICATOR_LEVELVALUE, 1, SellThreshold);
IndicatorSetDouble (INDICATOR_LEVELVALUE, 2, LevelMid);
IndicatorSetDouble (INDICATOR_LEVELVALUE, 3, LevelOB);
IndicatorSetDouble (INDICATOR_LEVELVALUE, 4, LevelOS);
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 0, 0x0055FF00); // lime dashed – buy
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 1, 0x00FF4444); // red dashed – sell
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 2, 0x007F7F7F); // gray dotted – mid
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 3, 0x00FF0000); // red – OB
IndicatorSetInteger(INDICATOR_LEVELCOLOR, 4, 0x0000FF00); // lime – OS
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 0, STYLE_DASH);
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 1, STYLE_DASH);
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 2, STYLE_DOT);
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 3, STYLE_SOLID);
IndicatorSetInteger(INDICATOR_LEVELSTYLE, 4, STYLE_SOLID);
//--- Tạo handles
handleRSI = iRSI(_Symbol, PERIOD_CURRENT, RSI_Length, PRICE_CLOSE);
handleMASlow = iMA (_Symbol, PERIOD_CURRENT, MA_Slow_Length, 0, MODE_SMA, handleRSI);
handleMAFast = iMA (_Symbol, PERIOD_CURRENT, MA_Fast_Length, 0, MODE_SMA, handleRSI);
if(handleRSI == INVALID_HANDLE || handleMASlow == INVALID_HANDLE || handleMAFast == INVALID_HANDLE)
{
Print("Lỗi tạo indicator handle trong RSI_System_Indicator");
return INIT_FAILED;
}
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| Indicator deinitialization |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
IndicatorRelease(handleRSI);
IndicatorRelease(handleMASlow);
IndicatorRelease(handleMAFast);
}
//+------------------------------------------------------------------+
//| Indicator calculation |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int copyFrom = (prev_calculated > 1) ? prev_calculated - 1 : 0;
int toCopy = rates_total - copyFrom;
//--- Copy RSI
if(CopyBuffer(handleRSI, 0, copyFrom, toCopy, BufRSI) < 0) return 0;
if(CopyBuffer(handleMASlow, 0, copyFrom, toCopy, BufMASlow) < 0) return 0;
if(CopyBuffer(handleMAFast, 0, copyFrom, toCopy, BufMAFast) < 0) return 0;
//--- Tô nền OB/OS (tương đương bgcolor trong Pine)
// MT5 không hỗ trợ bgcolor trực tiếp trong indicator buffer,
// ta dùng đối tượng background qua OnTimer hoặc đơn giản
// chú thích trong mô tả. Người dùng có thể thêm vùng tô thủ công
// qua tính năng "Levels""Fill Between Levels" trong settings.
return rates_total;
}
//+------------------------------------------------------------------+

Xet Storage Details

Size:
6.19 kB
·
Xet hash:
e6975977b1cbb7e98e3a0514aec6afcf10cacdcdff3fa61f358dc0f88cd3d26d

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.