//+------------------------------------------------------------------+ //| SmtDivergence.mq5 | //| Copyright 2025, Niquel Mendoza. | //| https://www.mql5.com/es/users/nique_372/news | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Niquel Mendoza." #property link "https://www.mql5.com/es/users/nique_372/news" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #define DEFGLOBAL_SIMPLE #include "Main.mqh" //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ input group "=== SMT Configuration ===" input int16_t InpSwingBefore = 4; // Swing: Velas anteriores input int16_t InpSwingAfter = 4; // Swing: Velas posteriores input int InpRange = 200; // Rango de búsqueda input color InpColorBuySwing = clrBlue; // Color swing alcista input color InpColorSellSwing = clrRed; // Color swing bajista input group "=== Símbolos a Comparar ===" input string InpSymbol2 = "GBPUSD"; // Símbolo 2 input bool InpOpenCharts = true; // Abrir gráficos automáticamente //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CSmtInterprete g_interprete(true); // Interprete int8_t idx_controler_d1 = INVALID_INDEX; int8_t idx_controler_curr = INVALID_INDEX; CSmtDivergence g_smt; // Smt //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Registramos timeframe D1 g_new_bar_manager.GetPosExecute(PERIOD_D1, idx_controler_d1); g_new_bar_manager.GetPosExecute(_Period, idx_controler_curr); //--- Crear concepto SMT if(!g_smt.Create(_Symbol, _Period, 0, 0, true)) { Print("Error: No se pudo crear CSmtDivergence"); return INIT_FAILED; } //--- Configurar SMT g_smt.Set( InpSwingBefore, InpSwingAfter, InpRange, InpColorBuySwing, InpColorSellSwing, &g_interprete ); //--- Agregar símbolo principal if(!g_smt.AddWithAutoWindow(_Symbol, false, 1, STYLE_SOLID, clrWhite)) { Print("Error: No se pudo agregar símbolo principal"); return INIT_PARAMETERS_INCORRECT; } //--- if(!g_smt.AddWithAutoWindow(InpSymbol2, InpOpenCharts, 2, STYLE_SOLID, clrLime)) { PrintFormat("Advertencia: No se pudo agregar %s", InpSymbol2); return INIT_PARAMETERS_INCORRECT; } else { PrintFormat("Símbolo agregado: %s", InpSymbol2); } return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Limpiar ICTGen_OnDeinitEvent(reason); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- const datetime curr_time = TimeCurrent(); g_new_bar_manager.Execute(curr_time); //--- if(CNewBarManager_IsNewBarM1(g_new_bar_manager) && CNewBarManager_IsNewBar(g_new_bar_manager, idx_controler_curr)) { const bool new_day = CNewBarManager_IsNewBar(g_new_bar_manager, idx_controler_d1); ICTGen_FuncionOnBarM1(new_day, curr_time); //--- g_smt.OnNewBar(); //--- Verificar si hay nueva divergencia if(g_smt.NuevoSmt()) { SmtHistorial smt = g_smt.SmtActual(); int result = smt.res; //--- if(result >= 1) { const string signal = (result == 1) ? "Venta" : "Compra"; PrintFormat("=== Nueva Divergencia SMT ==="); PrintFormat("Señal: %s (res=%d)", signal, result); PrintFormat("Símbolos divergentes:"); //--- Mostrar detalles de cada simbolo for(int i = 0; i < ArraySize(smt.idx); i++) { if(smt.idx[i] >= 0) { string sym = g_smt.GetSmtSymbolName(i); PrintFormat(" [%d] %s - idx: %d", i, sym, smt.idx[i]); } } PrintFormat("============================="); } } } } //+------------------------------------------------------------------+