Tách riêng EA và indicator
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Handles.mqh |
|
||||
//| Tạo / giải phóng indicator handles (RSI, EMA9/RSI, WMA45/RSI, |
|
||||
//| EMA200). EMA200 chỉ dùng qua CopyBuffer — không ChartIndicatorAdd |
|
||||
//| (tránh ERR_CHART_INDICATOR_CANNOT_ADD trong Tester / iCustom). |
|
||||
//| Tạo / giải phóng handle RSI, EMA9/WMA45 trên RSI, EMA200(close). |
|
||||
//| EMA200 chỉ CopyBuffer — không ChartIndicatorAdd. |
|
||||
//+------------------------------------------------------------------+
|
||||
#ifndef RSIMOM_HANDLES_MQH
|
||||
#define RSIMOM_HANDLES_MQH
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#define RSIMOM_SIGNALSCAN_MQH
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Quét signal từ bar `barsToScan` về bar 1, ghi vào buf_Signal / |
|
||||
//| buf_Trend / buf_EMA200 và tạo OBJ_ARROW khi có tín hiệu hợp lệ. |
|
||||
//| Quét signal từ bar `barsToScan` về bar 1, ghi mảng nội bộ |
|
||||
//| buf_Signal / buf_Trend / buf_EMA200 + vẽ OBJ_ARROW. |
|
||||
//+------------------------------------------------------------------+
|
||||
void SignalScan_Run(const int barsToScan,
|
||||
const int rates_total,
|
||||
@@ -118,7 +118,7 @@ void SignalScan_Run(const int barsToScan,
|
||||
|
||||
if (validBuy)
|
||||
{
|
||||
buf_Signal[i] = 1.0; // ghi tín hiệu cho EA đọc qua iCustom
|
||||
buf_Signal[i] = 1.0;
|
||||
|
||||
// Mũi tên lên (↑) đặt dưới đáy nến — tín hiệu BUY trong uptrend
|
||||
// ANCHOR_TOP: điểm anchor là đỉnh icon → arrow nằm xuôi xuống dưới price
|
||||
@@ -138,7 +138,7 @@ void SignalScan_Run(const int barsToScan,
|
||||
}
|
||||
else // validSell
|
||||
{
|
||||
buf_Signal[i] = -1.0; // ghi tín hiệu cho EA đọc qua iCustom
|
||||
buf_Signal[i] = -1.0;
|
||||
|
||||
// Mũi tên xuống (↓) đặt trên đỉnh nến — tín hiệu SELL trong downtrend
|
||||
// ANCHOR_BOTTOM: điểm anchor là đáy icon → arrow nằm ngược lên trên price
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| State.mqh |
|
||||
//| Toàn bộ biến global: indicator buffers, handles, hằng số, |
|
||||
//| state notification. KHÔNG chứa logic — chỉ khai báo. |
|
||||
//| Buffer plot (RSI, EMA9, WMA45) + mảng nội bộ cho alert/diag. |
|
||||
//| KHÔNG chứa logic — chỉ khai báo. |
|
||||
//+------------------------------------------------------------------+
|
||||
#ifndef RSIMOM_STATE_MQH
|
||||
#define RSIMOM_STATE_MQH
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Indicator buffers |
|
||||
//| Buffers hiển thị (plot) + mảng làm việc nội bộ |
|
||||
//+------------------------------------------------------------------+
|
||||
double buf_RSI[];
|
||||
double buf_EMA9[];
|
||||
double buf_WMA45[];
|
||||
double buf_Signal[]; // hidden — +1 BUY, -1 SELL, 0 none
|
||||
double buf_EMA200[]; // hidden — giá trị EMA200 (cho EA hiển thị)
|
||||
double buf_Trend[]; // hidden — +1 UP, -1 DOWN, 0 RANGE/SWITCHING
|
||||
double buf_Signal[]; // nội bộ — +1 BUY, -1 SELL, 0 none (Alerts)
|
||||
double buf_EMA200[]; // nội bộ — snapshot EMA200 theo bar (diag)
|
||||
double buf_Trend[]; // nội bộ — +1 UP, -1 DOWN, 0 RANGE (diag)
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Indicator handles |
|
||||
|
||||
Binary file not shown.
@@ -1,8 +1,7 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| RsiMomentumIndicator.mq5 |
|
||||
//| Hiển thị trong cửa sổ phụ: RSI14, EMA9(RSI), WMA45(RSI) |
|
||||
//| Trên chart chính: mũi tên giao cắt (EMA200 chỉ tính nội bộ). |
|
||||
//| Panel góc trên-phải: trend, giá trị RSI / EMA9 / WMA45 |
|
||||
//| Chỉ để hiển thị + trade thủ công: cửa sổ phụ RSI/EMA9/WMA45, |
|
||||
//| mũi tên + panel + cảnh báo entry. Không export buffer cho EA. |
|
||||
//| |
|
||||
//| Source code được tách thành các module trong thư mục Lib/: |
|
||||
//| Inputs.mqh — input parameters |
|
||||
@@ -14,9 +13,9 @@
|
||||
//| Diagnostics.mqh — log chẩn đoán lần đầu |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "RsiMomentumIndicator"
|
||||
#property version "1.10"
|
||||
#property version "1.20"
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 6
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 100
|
||||
@@ -67,9 +66,6 @@ int OnInit()
|
||||
SetIndexBuffer(0, buf_RSI, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, buf_EMA9, INDICATOR_DATA);
|
||||
SetIndexBuffer(2, buf_WMA45, INDICATOR_DATA);
|
||||
SetIndexBuffer(3, buf_Signal, INDICATOR_CALCULATIONS); // ẩn — phục vụ EA
|
||||
SetIndexBuffer(4, buf_EMA200, INDICATOR_CALCULATIONS); // ẩn — EMA200 cho EA
|
||||
SetIndexBuffer(5, buf_Trend, INDICATOR_CALCULATIONS); // ẩn — trend cho EA
|
||||
|
||||
ArraySetAsSeries(buf_RSI, true);
|
||||
ArraySetAsSeries(buf_EMA9, true);
|
||||
@@ -117,6 +113,14 @@ int OnCalculate(const int rates_total,
|
||||
const int minBars = InpWMA45Period + InpRSIPeriod + 5;
|
||||
if (rates_total < minBars) return 0;
|
||||
|
||||
// Mảng nội bộ (alert / diagnostics) — không bind buffer nên tự resize
|
||||
ArrayResize(buf_Signal, rates_total);
|
||||
ArrayResize(buf_EMA200, rates_total);
|
||||
ArrayResize(buf_Trend, rates_total);
|
||||
ArraySetAsSeries(buf_Signal, true);
|
||||
ArraySetAsSeries(buf_EMA200, true);
|
||||
ArraySetAsSeries(buf_Trend, true);
|
||||
|
||||
// Đảm bảo các source indicator đã tính xong (quan trọng khi cold-start
|
||||
// hoặc khi thị trường đóng — không có tick để retry)
|
||||
const int rsiBars = BarsCalculated(h_RSI);
|
||||
@@ -136,7 +140,7 @@ int OnCalculate(const int rates_total,
|
||||
}
|
||||
|
||||
// Chỉ copy số bar mà TẤT CẢ source (incl. EMA200) đã tính xong
|
||||
// → tránh CopyBuffer EMA200 fail giữa chừng làm buf_EMA200/buf_Trend stale
|
||||
// → tránh CopyBuffer EMA200 fail giữa chừng làm mảng nội bộ stale
|
||||
const int srcMin = MathMin(MathMin(MathMin(rsiBars, ema9Bars), wmaBars), ema200Bars);
|
||||
const int copyN = MathMin(srcMin, rates_total);
|
||||
if (copyN < minBars) return 0;
|
||||
|
||||
Reference in New Issue
Block a user