| //+------------------------------------------------------------------+
|
| //| FVG Visual Drawer EA (MT5) |
|
| //| SOLO análisis visual |
|
| //| No trading - No indicador |
|
| //+------------------------------------------------------------------+
|
| #property strict
|
|
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| #include "..\\Utils\\MetricSaver.mqh"
|
|
|
|
|
|
|
| /* Codigo hecho por ia ChatGpt
|
| Promt:
|
| Desarrolla un BOT (Expert Advisor) para MetaTrader 5 (MT5) que EXCLUSIVAMENTE detecte y dibuje Fair Value Gaps (FVG) en el gráfico.
|
| ⚠️ Este BOT NO debe ejecutar operaciones, NO debe abrir/cerrar trades y NO debe funcionar como indicador. Su única función es análisis visual mediante dibujo en el gráfico
|
| . Requisitos técnicos obligatorios: Implementado como Expert Advisor (EA) en MQL5. Detección y dibujo de FVG alcistas y bajistas.
|
| Funcionamiento rápido, eficiente y altamente optimizado. Capaz de trabajar con datos históricos y en tiempo real.
|
| Configuración personalizable desde el panel del BOT: Colores de los FVG. Opacidad / transparencia.
|
| Grosor y estilo de los rectángulos. Activar o desactivar FVG alcistas o bajistas. Timeframe de análisis. Aspectos visuales:
|
| Los FVG deben dibujarse como zonas (rectángulos) claras y limpias. Evitar redibujados innecesarios. El BOT debe actualizar los FVG solo cuando sea necesario.
|
| Buenas prácticas de desarrollo: Código limpio, modular y bien comentado. Uso eficiente de OnInit, OnTick y manejo de objetos gráficos.
|
| Optimización de loops y cálculos para mínimo consumo de CPU.
|
| Usa todo tu conocimiento avanzado en MQL5, optimización y Smart Money Concepts para crear un BOT profesional, estable y rápido,
|
| enfocado únicamente en dibujar Fair Value Gaps.
|
| */
|
|
|
|
|
| //---------------------------------------------------
|
| // INPUTS
|
| //---------------------------------------------------
|
| input ENUM_TIMEFRAMES InpTimeframe = PERIOD_M15;
|
| input bool ShowBullishFVG = true;
|
| input bool ShowBearishFVG = true;
|
|
|
| input color BullishColor = clrDodgerBlue;
|
| input color BearishColor = clrTomato;
|
|
|
| input int RectangleOpacity = 70; // 0-255
|
| input int RectangleBorder = 1;
|
| input ENUM_LINE_STYLE RectangleStyle = STYLE_SOLID;
|
|
|
| input int MaxBarsToScan = 500;
|
|
|
| //---------------------------------------------------
|
| datetime lastBarTime = 0;
|
|
|
| //---------------------------------------------------
|
| // INIT
|
| //---------------------------------------------------
|
| int OnInit()
|
| {
|
| CMetricsSave::Start(FILE_CODE5);
|
| ObjectsDeleteAll(0, "FVG_");
|
| return(INIT_SUCCEEDED);
|
| }
|
|
|
| //---------------------------------------------------
|
| // DEINIT
|
| //---------------------------------------------------
|
| void OnDeinit(const int reason)
|
| {
|
| ObjectsDeleteAll(0, "FVG_");
|
| CMetricsSave::Destroy();
|
| }
|
|
|
| //---------------------------------------------------
|
| // ON TICK
|
| //---------------------------------------------------
|
| void OnTick()
|
| {
|
| datetime currentBarTime = iTime(_Symbol, InpTimeframe, 0);
|
| if(currentBarTime == lastBarTime)
|
| return;
|
|
|
| lastBarTime = currentBarTime;
|
| DetectFVG();
|
| }
|
|
|
| //---------------------------------------------------
|
| // DETECCIÓN DE FVG
|
| //---------------------------------------------------
|
| void DetectFVG()
|
| {
|
| int bars = MathMin(MaxBarsToScan, iBars(_Symbol, InpTimeframe) - 3);
|
| if(bars <= 0) return;
|
|
|
| for(int i = bars; i >= 2; i--)
|
| {
|
| double high1 = iHigh(_Symbol, InpTimeframe, i+1);
|
| double low1 = iLow(_Symbol, InpTimeframe, i+1);
|
|
|
| double high3 = iHigh(_Symbol, InpTimeframe, i-1);
|
| double low3 = iLow(_Symbol, InpTimeframe, i-1);
|
|
|
| datetime timeStart = iTime(_Symbol, InpTimeframe, i+1);
|
| datetime timeEnd = iTime(_Symbol, InpTimeframe, i-1);
|
|
|
| if(ShowBullishFVG && low1 > high3)
|
| DrawFVG("FVG_BULL_", timeStart, timeEnd, high3, low1, BullishColor);
|
|
|
| if(ShowBearishFVG && high1 < low3)
|
| DrawFVG("FVG_BEAR_", timeStart, timeEnd, high1, low3, BearishColor);
|
| }
|
| }
|
|
|
| //---------------------------------------------------
|
| // DIBUJO DEL FVG
|
| //---------------------------------------------------
|
| void DrawFVG(string prefix, datetime t1, datetime t2, double p1, double p2, color baseColor)
|
| {
|
| string name = prefix + IntegerToString((long)t1);
|
|
|
| if(ObjectFind(0, name) != -1)
|
| return;
|
|
|
| uchar alpha = (uchar)MathMin(255, MathMax(0, RectangleOpacity));
|
| color finalColor = (color)ColorToARGB(baseColor, alpha);
|
|
|
| ObjectCreate(0, name, OBJ_RECTANGLE, 0, t1, p1, t2, p2);
|
| ObjectSetInteger(0, name, OBJPROP_COLOR, finalColor);
|
| ObjectSetInteger(0, name, OBJPROP_STYLE, RectangleStyle);
|
| ObjectSetInteger(0, name, OBJPROP_WIDTH, RectangleBorder);
|
| ObjectSetInteger(0, name, OBJPROP_BACK, true);
|
| ObjectSetInteger(0, name, OBJPROP_FILL, true);
|
| }
|