Mình thì tập tành viết cho vui, Tại mình thích DCA nên viết cho nó thôi.
Thỉnh thoảng có viết Hedging, nhồi lệnh theo xu hướng. Ae nào quan tâm thì pm mình nhé. AE nào chạy ổn thì gửi tiền cafe cho mình cũng đc. ko thì cũng ko sao.


R
Bỏ theo dõi bài viết
•••
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.
R
Theo dõi tác giả
15 phút trước
0 lượt xem
//+------------------------------------------------------------------+
//| 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);
}