Thống kê diễn đàn

Bài viết
112,753
Bình luận
807,740
Thành viên
110,401
Thành viên mới nhất
ningning

Thành viên trực tuyến

Không có thành viên nào trực tuyến.

Tôi có 1 mã code nhưng không thể hoàn chỉnh nó để chạy trên MQL4 nhờ ai đó am hiểu về code xin hãy giúp tôi biên tập nó để có thể chạy được.

Tôi có 1 mã code nhưng không thể hoàn chỉnh nó để chạy trên MQL4 nhờ ai đó am hiểu về code xin hãy giúp tôi biên tập nó để có thể chạy được.

Tôi có 1 mã code nhưng không thể hoàn chỉnh nó để chạy trên MQL4 nhờ ai đó am hiểu về code xin hãy giúp tôi biên tập nó để có thể chạy được.

Ruby12345

New Member
4
0
//+------------------------------------------------------------------+
//| PHONG.mq4 |
//| Copyright 2025, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue // Lỗi: không nên khai báo lại
// Input variables
input int length = 3;
input double bull = -0.51;
input double bear = 0.43;
input int atr_length = 3;

// Indicator buffers
double cviBuffer[];

// Function to calculate SMA
double SMA(double &source[], int period, int shift = 0) {
double sum = 0;
for (int iSMA = shift; iSMA < period + shift; iSMA++) { // Thay `iLoop` thành `iSMA`
sum += source[iSMA];
}
return sum / period;
}

// Function to calculate ATR
double ATR(int period) {
double atr = 0;
for (int iATR = 1; iATR <= period; iATR++) { // Thay `iLoop` thành `iATR`
atr += MathAbs(High[iATR] - Low[iATR]);
}
return atr / period;
}

int OnInit() {
// Set buffer
SetIndexBuffer(0, cviBuffer);
SetIndexStyle(0, DRAW_LINE);
SetIndexLabel(0, "CVI");
return(INIT_SUCCEEDED);
}

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[]) {

// Ensure we have enough data
if (rates_total < length + atr_length) {
return (0);
}

// Compute hl2
double hl2[];
ArraySetAsSeries(hl2, true);
for (int iHL2 = 0; iHL2 < rates_total; iHL2++) { // Thay `iLoop` thành `iHL2`
hl2[iHL2] = (high[iHL2] + low[iHL2]) / 2;
}

// Compute ATR
double vol[];
ArraySetAsSeries(vol, true);
for (int iVol = 0; iVol < rates_total; iVol++) { // Thay `iLoop` thành `iVol`
vol[iVol] = ATR(atr_length);
}

// Compute CVI
for (int iCVI = rates_total - 1; iCVI >= 0; iCVI--) { // Thay `iLoop` thành `iCVI`
double valC = SMA(hl2, length, iCVI);
double atr_val = vol[iCVI] * MathSqrt(length);
cviBuffer[iCVI] = (close[iCVI] - valC) / atr_val;
}

// Plot signals
for (int iSignal = rates_total - 1; iSignal >= 0; iSignal--) { // Thay `iLoop` thành `iSignal`
if (cviBuffer[iSignal] <= bull) {
if (iSignal < rates_total - 1 && cviBuffer[iSignal + 1] > bull) {
ObjectCreate(0, "bullSignal" + IntegerToString(iSignal), OBJ_LABEL, 0, time[iSignal], low[iSignal] - 5 * Point);
ObjectSetInteger(0, "bullSignal" + IntegerToString(iSignal), OBJPROP_COLOR, clrLime);
// Push notification
SendNotification("Bullish signal at " + TimeToString(time[iSignal], TIME_DATE | TIME_MINUTES) + " on " + Symbol());
// Screen alert
Alert("Bullish signal at " + TimeToString(time[iSignal], TIME_DATE | TIME_MINUTES) + " on " + Symbol());
}
}if (cviBuffer[iSignal] >= bear) {
if (iSignal < rates_total - 1 && cviBuffer[iSignal + 1] < bear) {
ObjectCreate(0, "bearSignal" + IntegerToString(iSignal), OBJ_LABEL, 0, time[iSignal], high[iSignal] + 5 * Point);
ObjectSetInteger(0, "bearSignal" + IntegerToString(iSignal), OBJPROP_COLOR, clrRed);

// Push notification
SendNotification("Bearish signal at " + TimeToString(time[iSignal], TIME_DATE | TIME_MINUTES) + " on " + Symbol());
// Screen alert
Alert("Bearish signal at " + TimeToString(time[iSignal], TIME_DATE | TIME_MINUTES) + " on " + Symbol());
}
}
}

return (rates_total);
}
 
 

Giới thiệu sách Trading hay
Bộ sách Giao Dịch Thực Chiến của Trader Chuyên Nghiệp

Bộ sách tổng hợp những phương pháp giao dịch hiệu quả cao của những Trader chuyên nghiệp

BÌNH LUẬN MỚI NHẤT

AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

Back
Bên trên

Miễn trừ trách nhiệm

Tất cả nội dung trên website này đều vì mục đích cung cấp thông tin và không phải lời khuyên đầu tư.

Tại Việt Nam, giao dịch CFD forex có các rủi ro nhất định, trong đó bao gồm rủi ro về pháp lý. Độc giả nên tìm hiểu kỹ trước khi đưa ra quyết định tham gia.