Detección del Patrón de Spike Alcista
Creación de la Zona
-
Se dibuja un rectángulo azul desde el rango alto/bajo de las 3 velas.
-
Se dibuja una línea de entrada horizontal verde lima al precio de apertura de la vela del medio (2ª vela).
-
La línea se extiende hacia el futuro hasta que el precio regrese.
-

EXPLICACIÓN DE ENTRADAS
mq5
input color BoxColor = clrBlue; // Color del rectángulo del patrón de 3 velas
input color EntryLineColor = clrLime; // Color de la línea de entrada
input ENUM_LINE_STYLE EntryLineStyle = STYLE_SOLID; // Estilo de la línea de entrada
input int BoxWidth = 2; // Ancho del borde del rectángulo
input int EntryLineWidth = 2; // Ancho de la línea de entrada
input int EntryLineLength = 200; // Extensión de la línea de mitigación
IDEA PRINCIPAL
Buscamos un patrón alcista de 3 velas:
1. Primera vela – fuerte alcista (spike)
2. Segunda vela – retroceso bajista
3. Tercera vela – fuerte spike alcista nuevamente
Cuando esto aparece, dibujamos:
- Un rectángulo alrededor del patrón
- Una línea horizontal en la apertura de la 2ª vela (punto de entrada)
Una vez que el precio regresa a esa línea ("mitigación"), cortamos la línea y evitamos redibujarla.
ESTRUCTURAS DE DATOS
struct PatternInfo {
datetime time; // Tiempo del patrón
double entry; // Precio de entrada (apertura de la 2ª vela)
double high; // Máximo de las 3 velas
double low; // Mínimo de las 3 velas
bool mitigated; // ¿El precio ha vuelto al nivel de entrada?
};
CArrayObj activePatterns;
Usamos una struct `PatternInfo` para rastrear cada patrón válido y almacenarlo en un array. Esto ayuda a evitar un procesamiento repetido.
FUNCIÓN DE INICIO
int OnInit() {
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
ArrayInitialize(activePatterns, 0);
return INIT_SUCCEEDED;
}
Establecemos la precisión del indicador y preparamos nuestro array.
DETECCIÓN DEL PATRÓN (EN CADA TICK)
```mq5
for (int i = limit - 3; i >= 0; i--) {
``` Recorremos las velas y buscamos 3 barras atrás.
```mq5
if (isBullish(i+2) && isBearish(i+1) && isBullish(i))
```
Verificamos si las últimas 3 velas encajan en el patrón de spike: Verde-Rojo-Verde.
```mq5
double high = MathMax(MathMax(High[i], High[i+1]), High[i+2]);
double low = MathMin(MathMin(Low[i], Low[i+1]), Low[i+2]);
double entry = Open[i+1];
```
Extraemos el alto/bajo para el rectángulo y el nivel de entrada de la 2ª (vela del medio).
```mq5
PatternInfo *pattern = new PatternInfo;
pattern.time = Time[i];
pattern.entry = entry;
pattern.high = high;
pattern.low = low;
pattern.mitigated = false;
```
Crearemos y añadiremos este patrón a nuestra lista.
DIBUJAR CAJA Y LÍNEA
```mq5
string boxName = "Box_" + IntegerToString(Time[i]);
ObjectCreate(0, boxName, OBJ_RECTANGLE, 0, Time[i+2], high, Time[i], low);
```
Dibujamos el rectángulo (caja) desde el patrón de 3 velas.
```mq5
string lineName = "EntryLine_" + IntegerToString(Time[i]);
ObjectCreate(0, lineName, OBJ_TREND, 0, Time[i], entry, Time[i] + PeriodSeconds() * EntryLineLength, entry);
```
Dibujamos la línea de entrada desde la apertura de la 2ª vela hacia adelante en el tiempo.
VERIFICACIÓN DE MITIGACIÓN (EN CADA TICK)
```mq5
// Recorremos todos los patrones:
for (int p = 0; p < activePatterns.Total(); p++) {
PatternInfo *pt = (PatternInfo*)activePatterns.At(p);
``` Si no ha sido mitigado, verificamos:
```mq5
if (!pt.mitigated && Low[0] <= pt.entry)
```
Si el precio actual toca el nivel de entrada:
```mq5
pt.mitigated = true;
ObjectDelete("EntryLine_" + IntegerToString(pt.time));
``` Eliminamos la línea original.
```mq5
ObjectCreate(0, "MitigatedLine_" + IntegerToString(pt.time), OBJ_TREND, 0,
pt.time, pt.entry,
Time[0], pt.entry);
```
Crearemos una línea corta que muestra dónde ocurrió la mitigación.
FUNCIONES AUXILIARES ### Verificar Alcista/Bajista:
```mq5
bool isBullish(int i) {
return Close[i] > Open[i];
}
bool isBearish(int i) {
return Close[i] < Open[i];
}
```
Este indicador es simple pero poderoso:
- Detecta el comportamiento real de spikes en Boom
- Visualiza las entradas inteligentes del dinero
- Detecta automáticamente la mitigación
Ahora puedes probarlo en vivo en Boom 500 o Boom 1000.