GW News Filter
- Bibliotecas
- Jose Martinez Hernandez
- Versión: 1.0
GW News Filter (filtro de noticias)
Filtra la operativa en torno a noticias de alto impacto. Evita entradas/salidas en ventanas de riesgo usando el Calendar API de MetaTrader o tus propios archivos CSV.
Funciona en real, demo y Strategy Tester · Fuente: API o CSV · Archivos por divisa · Flags Entrada/Salida · Diagnóstico (0–4)
Características
Funciona en cuentas reales, demo y Strategy Tester
Elige entre:
- 0 = Auto (API en real/demo, CSV en Strategy Tester)
- 1 = API (calendario integrado de MetaTrader)
- 2 = CSV (un archivo por divisa, ej. EUR.csv, USD.csv, ALL.csv)
Configurable:
- Importancia mínima (Low, Moderate, High)
- Segundos de ventana antes/después de la noticia
- Incluir eventos globales “ALL”
- Flags separados para entradas y salidas
- Wrapper ligero para integración sencilla
- Logs de diagnóstico (niveles 0–4) para pruebas y depuración
Instalación
- Copia MQL5/Libraries/GWNewsFilterLib.ex5
- Copia MQL5/Include/Greaterwaves/GWNewsFilterLib.mqh
- Incluye en tu EA/indicador:
#include <Greaterwaves/GWNewsFilterLib.mqh>
Inicio rápido
Crea el filtro una vez (ej. en OnInit). Si pruebas con CSV, define la carpeta con SetCsvLocation().
int OnInit() { if(!g.Create(_Symbol, InpFilterEntry, InpFilterExit, InpMinImp, InpIncludeAll, InpBefore, InpAfter, InpDiagLevel, InpSource)) { Print("GWNF: failed to create instance (Did you copy GWNewsFilterLib.ex5 into MQL5/Libraries/ ?)"); return(INIT_FAILED); } // If using CSV (or running in Tester), set the CSV location if(InpSource==1 || (int)MQLInfoInteger(MQL_TESTER)!=0) { if(!g.SetCsvLocation(InpCsvBaseRel, InpCsvUseCommon)) Print("GWNF: SetCsvLocation() failed."); } return(INIT_SUCCEEDED); }
Después, reconstruye la ventana una vez por barra y actúa según el estado:
void OnTick() { datetime bar = (datetime)iTime(_Symbol, _Period, 0); if(bar == g_last) return; g_last = bar; if(!g.RebuildWindow()) { Print("GWNF: RebuildWindow() returned false."); return; } const int active = g.GetFilteringEventsCount(); if(active > 0) { // Filtro activo - Esquiva entradas y gestiona salidas } else { // Filtro no activo - no hay noticias en ventana } }
Guía de preparación de CSV
Cada fila del CSV debe contener estas 16 columnas, en este orden exacto:
- VALUE_ID → ID numérico único (ej. `10001`)
- EVENT_ID → ID numérico único del evento (ej. `20001`)
- TIME → Hora en formato `YYYY.MM.DD HH:MM:SS`
- PERIOD → Periodo (puede quedar vacío)
- REVISION → Número de revisión (normalmente `0`)
- ACTUAL → Valor actual (vacío si no se conoce)
- PREVIOUS → Valor previo (vacío si no se conoce)
- REVISED_PREV → Valor previo revisado
- FORECAST → Valor previsto
- IMPACT_TYPE → Entero (0=none, 1=positive, 2=negative, 3=neutral)
- CURRENCY → Código de divisa (`USD`, `EUR`, `JPY`, `ALL`)
- COUNTRY_CODE → Código de país (`US`, `EU`, `GB`, …)
- COUNTRY_ID → ID numérico (puede ser `0`)
- IMPORTANCE → `LOW`, `MODERATE`, o `HIGH`
- EVENT_CODE → Identificador corto (`cpi`, `gdp`, `trade-balance`)
- NAME → Nombre del evento
Ejemplo de filas:
10001;20001;2025.08.28 12:30:00;;0;3.4;3.2;;3.5;0;USD;US;0;HIGH;cpi;Consumer Price Index (YoY) 10002;20002;2025.08.28 14:00:00;;0;1.8;2.0;;2.1;0;USD;US;0;MODERATE;housing;Housing Starts 10003;20003;2025.08.28 15:00:00;;0;;; ;0.9;0;EUR;EU;0;HIGH;confidence;Consumer Confidence Index
Explicación:
- El primer evento es un CPI USD de alto impacto.
- El segundo evento es un dato de vivienda de impacto moderado.
- El tercero es un índice de confianza EUR de alto impacto.
Nombres y ubicación de archivos
Coloca un archivo CSV por divisa (ej. USD.csv, EUR.csv) dentro de una carpeta.
La carpeta puede estar en:
- Common\Files\NEWS\ (compartida por todos los terminales), o
- MQL5\Files\NEWS\ (local a un terminal).
Se configura con:
g.SetCsvLocation("NEWS", true); // "true" = usa Common\Files
Diagnóstico
- 0 = silencioso
- 1 = solo errores críticos
- 2 = init + cuando el filtro está activo
- 3 = añade logs “fuera de noticias”
- 4 = detalle completo (lista todos los eventos)
Notas importantes
- Aunque no uses todos los valores (ej. VALUE_ID), debes mantener el orden de columnas y delimitadores.
- Los campos vacíos están permitidos — conserva el separador `;`.
- El parser espera separadores `;`, igual que CSV en MetaTrader.
- IMPORTANCE debe ser: LOW, MODERATE, HIGH.
Wrapper Header (copia en MQL5/Include/Greaterwaves/GWNewsFilterLib.mqh)
//+------------------------------------------------------------------+ //| GWNewsFilterLib.mqh | //| Public wrapper for GWNewsFilterLib.ex5 binary | //| (c) GreaterWaves - José Martínez Hernández | //+------------------------------------------------------------------+ // // CÓMO USAR // 1) Copia este archivo a: MQL5/Include/Greaterwaves/GWNewsFilterLib.mqh // 2) Copia el binario a: MQL5/Libraries/GWNewsFilterLib.ex5 // 3) En tu EA/Indicador: // #include <Greaterwaves/GWNewsFilterLib.mqh> // // Ejemplo: // // GWNewsFilter nf; // if(nf.Create(_Symbol, true, false, // 2, // minImportance (0=None,1=Low,2=Moderate,3=High) // true, // includeGlobalAll // 900,900,// secondsBefore/After // 3, // diagnosticLevel (0-4) // 0)) // forcedSource (0=Auto,1=CSV,2=API) // { // nf.SetCsvLocation("NEWS", true); // Optional custom CSV path // nf.RebuildWindow(); // if(nf.IsFilteringNow(true,false)) // Print("Filter active on entry"); // nf.UpdateChartCommentMinimal(); // } // // =============================================================== // IMPORTS from binary library // =============================================================== #import "GWNewsFilterLib.ex5" int GWFilter_Create(string symbol, bool filterEntry, bool filterExit, int minImportance, bool includeGlobalAll, int secondsBefore, int secondsAfter, int diagnosticLevel, int forcedSource); bool GWFilter_Destroy(int handle); bool GWFilter_RebuildWindow(int handle); bool GWFilter_IsBlockingNow(int handle, bool forEntry, bool forExit); int GWFilter_GetBlockingEventsCount(int handle); int GWFilter_TotalInWindow(int handle); bool GWFilter_GetWindowEventAt(int handle, int index, long &value_id, long &event_id, datetime &time, string ¤cy, string &country_code, string &event_code, string &name, int &importance); bool GWFilter_SetDiagnosticLevel(int handle, int level); bool GWFilter_SetForcedSource (int handle, int forcedSource); bool GWFilter_SetBlockFlags (int handle, bool filterEntry, bool filterExit); bool GWFilter_BuildBlockingComment(int handle, string &out_comment); bool GWFilter_UpdateChartCommentMinimal(int handle); bool GWFilter_SetCsvLocation(int handle, string baseRel, bool useCommon); #import // =============================================================== // Object-oriented wrapper for easier usage in EAs/Indicators // =============================================================== class GWNewsFilter { private: int m_h; // internal handle to binary object public: GWNewsFilter(): m_h(0) {} // Create instance with settings bool Create(string symbol, bool filterEntry, bool filterExit, int minImportance = 2, bool includeGlobalAll= true, int secondsBefore = 900, int secondsAfter = 900, int diagnosticLevel = 2, int forcedSource = 0) { m_h = GWFilter_Create(symbol, filterEntry, filterExit, minImportance, includeGlobalAll, secondsBefore, secondsAfter, diagnosticLevel, forcedSource); return (m_h > 0); } // Destroy instance bool Destroy() { if(m_h<=0) return false; bool ok=GWFilter_Destroy(m_h); m_h=0; return ok; } // Refresh window of upcoming events bool RebuildWindow() { return (m_h>0 ? GWFilter_RebuildWindow(m_h) : false); } // Check if filter is active now (entry/exit) bool IsFilteringNow(bool forEntry, bool forExit) { return (m_h>0 ? GWFilter_IsBlockingNow(m_h, forEntry, forExit) : false); } // Number of filtering events currently active int GetFilteringEventsCount(){ return (m_h>0 ? GWFilter_GetBlockingEventsCount(m_h) : -1); } // Total number of events in the current window int TotalInWindow() { return (m_h>0 ? GWFilter_TotalInWindow(m_h) : -1); } // Get details of an event at index bool GetWindowEventAt(int index, long &value_id, long &event_id, datetime &time, string ¤cy, string &country_code, string &event_code, string &name, int &importance) { return (m_h>0 ? GWFilter_GetWindowEventAt(m_h, index, value_id, event_id, time, currency, country_code, event_code, name, importance) : false); } // Change diagnostic log level bool SetDiagnosticLevel(int level){ return (m_h>0 ? GWFilter_SetDiagnosticLevel(m_h, level) : false); } // Force data source (Auto, CSV, API) bool SetForcedSource (int forced){ return (m_h>0 ? GWFilter_SetForcedSource (m_h, forced) : false); } // Enable/disable filtering for entry/exit bool SetFilterFlags (bool fe, bool fx){ return (m_h>0 ? GWFilter_SetBlockFlags(m_h, fe, fx) : false); } // Build a minimal comment string when filter is active bool BuildFilteringComment(string &out_comment){ out_comment=""; return (m_h>0 ? GWFilter_BuildBlockingComment(m_h, out_comment) : false); } // Update chart comment automatically (only when active) bool UpdateChartCommentMinimal(){ return (m_h>0 ? GWFilter_UpdateChartCommentMinimal(m_h) : false); } // Set CSV folder location bool SetCsvLocation(const string baseRel, const bool useCommon=true) { return (m_h>0 ? GWFilter_SetCsvLocation(m_h, baseRel, useCommon) : false); } // Return internal handle int Handle() const { return m_h; } };
Ejemplo de EA con uso mínimo
// Minimal demo usage #include <Greaterwaves/GWNewsFilterLib.mqh> GWNewsFilter g; int OnInit() { g.Create(_Symbol, true, false, 2, true, 900, 900, 2, 0); g.SetCsvLocation("NEWS", true); // if using CSV return INIT_SUCCEEDED; } void OnTick() { if(g.RebuildWindow()) { if(g.GetFilteringEventsCount()>0) Print("Filter active - skip trading"); } }
Soporte: https://academy.greaterwaves.com

