//+------------------------------------------------------------------+ //| Koncorde_MT4.mq4 | //| | //+------------------------------------------------------------------+ #property copyright "Basado en Koncorde de Xavier García (Blai5)" #property version "2.01" #property description "Koncorde - Sistema de Manos Fuertes vs Débiles" #property strict #property indicator_separate_window #property indicator_buffers 12 #property indicator_color1 clrSaddleBrown // Montaña - Tendencia #property indicator_color2 clrForestGreen // Prado - Manos Débiles #property indicator_color3 clrDodgerBlue // Agua - Manos Fuertes #property indicator_color4 clrRed // Señal - Media Móvil #property indicator_color5 clrGold // Patrón Primavera #property indicator_color6 clrLime // Patrón Espejo #property indicator_color7 clrDarkOrange // Patrón Corte Alcista #property indicator_color8 clrDarkViolet // Patrón Corte Bajista #property indicator_color9 clrGray // Línea Cero #property indicator_color10 clrLightPink // Fondos Sobrecompra #property indicator_color11 clrLightBlue // Fondos Sobreventa #property indicator_color12 clrYellow // Patrón Abrazo Oso //---- Input Parameters input int PeriodoMontana = 14; // Periodo para la Montaña input int PeriodoPrado = 14; // Periodo para el Prado input int PeriodoAgua = 14; // Periodo para el Agua input int PeriodoSeñal = 13; // Periodo Media Señal input bool MostrarPatrones = true; // Mostrar Patrones input bool MostrarFlechas = true; // Mostrar Flechas input bool AlertasSonido = false; // Alertas por Sonido //---- Buffers Principales Koncorde double MontanaBuffer[]; // Tendencia principal double PradoBuffer[]; // Manos débiles (retail) double AguaBuffer[]; // Manos fuertes (instituciones) double SeñalBuffer[]; // Media móvil señal //---- Buffers para Patrones double PatronEspejoBuffer[]; double PatronPrimaveraBuffer[]; double PatronCorteAlcistaBuffer[]; double PatronCorteBajistaBuffer[]; double PatronAbrazoOsoBuffer[]; double FondoSobrecompraBuffer[]; double FondoSobreventaBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { Print("=== KONCORDE MT4 - INICIALIZANDO ==="); // Buffers Principales - USAR DRAW_LINE PARA PRUEBA SetIndexBuffer(0, MontanaBuffer); SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 3); // Cambiado a DRAW_LINE para prueba SetIndexLabel(0, "Montaña - Tendencia"); SetIndexBuffer(1, PradoBuffer); SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2); // Cambiado a DRAW_LINE para prueba SetIndexLabel(1, "Prado - Manos Débiles"); SetIndexBuffer(2, AguaBuffer); SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2); // Cambiado a DRAW_LINE para prueba SetIndexLabel(2, "Agua - Manos Fuertes"); SetIndexBuffer(3, SeñalBuffer); SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 2); SetIndexLabel(3, "Señal - Media"); // Buffers de Patrones SetIndexBuffer(4, PatronEspejoBuffer); SetIndexStyle(4, DRAW_ARROW, STYLE_SOLID, 3); SetIndexArrow(4, 108); // Diamante SetIndexLabel(4, "Patrón Espejo"); SetIndexBuffer(5, PatronPrimaveraBuffer); SetIndexStyle(5, DRAW_ARROW, STYLE_SOLID, 3); SetIndexArrow(5, 110); // Estrella SetIndexLabel(5, "Patrón Primavera"); SetIndexBuffer(6, PatronCorteAlcistaBuffer); SetIndexStyle(6, DRAW_ARROW, STYLE_SOLID, 3); SetIndexArrow(6, 233); // Flecha arriba SetIndexLabel(6, "Corte Alcista"); SetIndexBuffer(7, PatronCorteBajistaBuffer); SetIndexStyle(7, DRAW_ARROW, STYLE_SOLID, 3); SetIndexArrow(7, 234); // Flecha abajo SetIndexLabel(7, "Corte Bajista"); SetIndexBuffer(8, PatronAbrazoOsoBuffer); SetIndexStyle(8, DRAW_ARROW, STYLE_SOLID, 3); SetIndexArrow(8, 115); // Cruz SetIndexLabel(8, "Abrazo Oso"); // Buffers de Fondos SetIndexBuffer(9, FondoSobrecompraBuffer); SetIndexStyle(9, DRAW_HISTOGRAM, STYLE_SOLID, 1); SetIndexLabel(9, "Sobrecompra"); SetIndexBuffer(10, FondoSobreventaBuffer); SetIndexStyle(10, DRAW_HISTOGRAM, STYLE_SOLID, 1); SetIndexLabel(10, "Sobreventa"); // Rango del Indicador - MÁS PEQUEÑO para mejor visualización IndicatorSetDouble(INDICATOR_MINIMUM, -50); IndicatorSetDouble(INDICATOR_MAXIMUM, 50); // Niveles de Referencia IndicatorSetInteger(INDICATOR_LEVELS, 5); IndicatorSetDouble(INDICATOR_LEVELVALUE, 0, 30); IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, 10); IndicatorSetDouble(INDICATOR_LEVELVALUE, 2, 0); IndicatorSetDouble(INDICATOR_LEVELVALUE, 3, -10); IndicatorSetDouble(INDICATOR_LEVELVALUE, 4, -30); IndicatorShortName("Koncorde MT4"); Print("Sistema Koncorde inicializado correctamente"); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { if(rates_total < 50) { Print("Esperando más datos... Disponibles: ", rates_total); return(0); } int limit; if(prev_calculated == 0) { limit = rates_total - 1; Print("Inicializando desde el inicio. Barras: ", rates_total); // Inicializar buffers con valores por defecto for(int i = 0; i < rates_total; i++) { MontanaBuffer[i] = 0; PradoBuffer[i] = 0; AguaBuffer[i] = 0; SeñalBuffer[i] = 0; PatronEspejoBuffer[i] = EMPTY_VALUE; PatronPrimaveraBuffer[i] = EMPTY_VALUE; PatronCorteAlcistaBuffer[i] = EMPTY_VALUE; PatronCorteBajistaBuffer[i] = EMPTY_VALUE; PatronAbrazoOsoBuffer[i] = EMPTY_VALUE; FondoSobrecompraBuffer[i] = EMPTY_VALUE; FondoSobreventaBuffer[i] = EMPTY_VALUE; } } else { limit = rates_total - prev_calculated; if(limit < 1) limit = 1; } // Calcular indicadores para cada barra for(int i = limit; i >= 0; i--) { // 1. CALCULAR INDICADORES BÁSICOS double rsi = iRSI(Symbol(), 0, PeriodoMontana, PRICE_CLOSE, i); double stoch = iStochastic(Symbol(), 0, 14, 3, 3, MODE_SMA, 0, MODE_MAIN, i); double williams = CalcularWilliams(i, rates_total, high, low, close); // 2. CALCULAR MONTANA (Tendencia Principal) // Usar RSI y Stochastic para la tendencia MontanaBuffer[i] = (rsi - 50) * 0.8 + (stoch - 50) * 0.4; // 3. CALCULAR PRADO (Manos Débiles) // Manos débiles reaccionan al precio y volumen PradoBuffer[i] = (williams * 0.5) + (rsi - 50) * 0.3; // 4. CALCULAR AGUA (Manos Fuertes) // Manos fuertes usan estrategias más complejas AguaBuffer[i] = (rsi - 50) * 0.6 - (williams * 0.4); // 5. CALCULAR SEÑAL (Media Móvil Simple) SeñalBuffer[i] = iMAOnArray(MontanaBuffer, 0, PeriodoSeñal, 0, MODE_SMA, i); // 6. DETECTAR PATRONES if(MostrarPatrones && i < rates_total - 1) DetectarPatrones(i); // 7. CALCULAR FONDOS DE COLOR CalcularFondos(i, williams); // DEBUG: Imprimir valores cada 50 barras if(i % 50 == 0 && i < 10) { Print("Barra ", i, " - Montana: ", MontanaBuffer[i], ", Prado: ", PradoBuffer[i], ", Agua: ", AguaBuffer[i], ", Señal: ", SeñalBuffer[i]); } } // Debug de la barra actual Print("=== VALORES ACTUALES ==="); Print("Barra 0 - Montana: ", MontanaBuffer[0], ", Prado: ", PradoBuffer[0], ", Agua: ", AguaBuffer[0], ", Señal: ", SeñalBuffer[0]); return(rates_total); } //+------------------------------------------------------------------+ //| Función: Calcular Williams %R | //+------------------------------------------------------------------+ double CalcularWilliams(int i, int rates_total, const double &high[], const double &low[], const double &close[]) { if(i <= rates_total - 14) { int start = i + 13; double highest = high[ArrayMaximum(high, 14, start)]; double lowest = low[ArrayMinimum(low, 14, start)]; if(highest != lowest && highest != 0 && lowest != 0) { double williams = ((close[i] - highest) / (highest - lowest)) * -100; return williams; } } return 0; } //+------------------------------------------------------------------+ //| Función: Detectar Patrones Koncorde | //+------------------------------------------------------------------+ void DetectarPatrones(int i) { // Reiniciar buffers de patrones PatronEspejoBuffer[i] = EMPTY_VALUE; PatronPrimaveraBuffer[i] = EMPTY_VALUE; PatronCorteAlcistaBuffer[i] = EMPTY_VALUE; PatronCorteBajistaBuffer[i] = EMPTY_VALUE; PatronAbrazoOsoBuffer[i] = EMPTY_VALUE; // 1. PATRÓN ESPEJO (Manos fuertes compran, débiles venden) if(AguaBuffer[i] > 10 && PradoBuffer[i] < -10 && MontanaBuffer[i] > 0) { PatronEspejoBuffer[i] = 35; if(AlertasSonido && i == 0) Alert("PATRÓN ESPEJO DETECTADO - COMPRA"); } // 2. PATRÓN CORTE ALCISTA (Señal cruza por debajo de montaña) if(SeñalBuffer[i] < MontanaBuffer[i] && SeñalBuffer[i+1] >= MontanaBuffer[i+1]) { PatronCorteAlcistaBuffer[i] = 25; if(AlertasSonido && i == 0) Alert("CORTE ALCISTA DETECTADO"); } // 3. PATRÓN CORTE BAJISTA (Señal cruza por encima de montaña) if(SeñalBuffer[i] > MontanaBuffer[i] && SeñalBuffer[i+1] <= MontanaBuffer[i+1]) { PatronCorteBajistaBuffer[i] = -25; if(AlertasSonido && i == 0) Alert("CORTE BAJISTA DETECTADO"); } // 4. PATRÓN PRIMAVERA (Corte alcista + Prado sobre Montana) if(PatronCorteAlcistaBuffer[i] != EMPTY_VALUE && PradoBuffer[i] > MontanaBuffer[i]) { PatronPrimaveraBuffer[i] = 30; if(AlertasSonido && i == 0) Alert("PATRÓN PRIMAVERA DETECTADO - FUERTE COMPRA"); } // 5. PATRÓN ABRAZO DEL OSO (Manos fuertes venden, débiles compran) if(AguaBuffer[i] < -10 && PradoBuffer[i] > 10 && MontanaBuffer[i] < 0) { PatronAbrazoOsoBuffer[i] = -35; if(AlertasSonido && i == 0) Alert("ABRAZO DEL OSO DETECTADO - VENTA"); } } //+------------------------------------------------------------------+ //| Función: Calcular Fondos de Color | //+------------------------------------------------------------------+ void CalcularFondos(int i, double williams) { FondoSobrecompraBuffer[i] = EMPTY_VALUE; FondoSobreventaBuffer[i] = EMPTY_VALUE; // Sobrecompra if(williams > -20) { FondoSobrecompraBuffer[i] = 40; } // Sobreventa else if(williams < -80) { FondoSobreventaBuffer[i] = -40; } } //+------------------------------------------------------------------+ //| Funciones Auxiliares | //+------------------------------------------------------------------+ int ArrayMaximum(const double &array[], int count, int start) { int index = start; double max = array[start]; int end = MathMin(start + count, ArraySize(array)); for(int i = start; i < end; i++) { if(array[i] > max) { max = array[i]; index = i; } } return index; } int ArrayMinimum(const double &array[], int count, int start) { int index = start; double min = array[start]; int end = MathMin(start + count, ArraySize(array)); for(int i = start; i < end; i++) { if(array[i] < min) { min = array[i]; index = i; } } return index; } //+------------------------------------------------------------------+ //| Deinit function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { Print("Koncorde MT4 finalizado. Razón: ", reason); }