Multiple Fibos panel

 

Hi there!
I am a newbie in MQL4 although I have managed to do some ea or indicator, now I need to make a "Panel of multiple Fibos", this panel has several buttons to draw different fibos of different colors and another button to clean the chat. In principle and taking advantage of the original Mql4 Fibo code that I adapted and I have managed to create the panel with its buttons, the button to delete the graphic, the latter works perfectly but the fibos buttons are where I need help, I get it to draw the colored Fibos but now I need you to draw three rectangles that are modified with the Fibo at the same time, these rectangles their point of origin is the same point of the beginning of Level 0, 61.8 and 100 of the Fibo, their height is always half the distance from Level 61.8 to 100, that is, a level of increase 19.1 and its initial length of 2 days from the beginning of the Fibo, another point is that the Fibo when it is drawn that I activate to move it and not where it is initially generated, can you help me, I am doing tests and reading 1001 document but I can't find anything for these last points. I attach the code obtained up to this point and functional, so you can see what it does to me and I still need to obtain.

Thank you very much in advance.
And sorry for my English.

Here you have the code so far.

//+------------------------------------------------------------------+
//|                                                 MHS_Fibos_v0.mq4 |
//|                      Copyright Septiembre, 2021, M. de los Heros |
//|                                              m.delosheros@gmx.es |
//|                                             © ® Code Nr.: 202198 |
//+------------------------------------------------------------------+
#property copyright "M. de los Heros"
#property link      "m.delosheros@gmx.es"
#property icon      "\Images\The Bluefather.ico";
#property description "Creamos un panel de Fibos configurados"
#property version     "0"
#property strict
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
//--- input parameters of the script
input string          InpName="FiboLevels";      // Nombre del objeto
input int             InpDate1=70;               // Fecha del 1er punto,%
input int             InpPrice1=45;              // Precio del 1er punto,%
input int             InpDate2=90;               // Fecha del 2º punto,%
input int             InpPrice2=85;              // Precio del 2º punto,%
input color           InpColor=clrRed;           // Color del objeto
input ENUM_LINE_STYLE InpStyle=STYLE_DASHDOTDOT; // Estilo de línea
input int             InpWidth=1;                // Grueso de línea
input bool            InpBack=false;             // Objeto de fondo
input bool            InpSelection=true;         // Resaltar para mover
input bool            InpRayRight=false;         // Continuación del objeto a la derecha
input bool            InpHidden=true;            // Oculto en la lista de objetos
input long            InpZOrder=0;               // Prioridad para el clic del mouse
input color           clr = clrBlack;            // Color del objeto

//+------------------------------------------------------------------+
//| Constantes FIBO                                                  |
//+------------------------------------------------------------------+
extern double FiboLevel1=0.000;
extern double FiboLevel2=0.382;
extern double FiboLevel3=0.618;
extern double FiboLevel4=1.000;
extern double FiboLevel5=1.382;
extern double FiboLevel6=1.618;
extern double FiboLevel7=0.191;
extern double FiboLevel8=1.191;
extern double FiboLevel9=0.809;


extern color  Fibo1Color= clrBlack;
extern color  levelColor= clrBlack;
extern color Zcolor;

double fiboPrice1;
double fiboPrice2;
      
double fiboPriceDiff;
string fiboValue0;
string fiboValue38;
string fiboValue61;
string fiboValue100;
string fiboValue138;
string fiboValue161;
string fiboValue19;
string fiboValue119;
string fiboValue89;


//string Copyright="\xA9 WWW.BEST-METATRADER-INDICATORS.COM";
  
string MPrefix="FI";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
//+-----------------------------------------------------------------+
//+--- Boton Limpiar chart de objetos "Limpiar Chart"

   CrearBoton("Boton", 1730, 22, 135, 16,  clrBlack,  clrChartreuse, clrBlack,"ORBITRON",9,"Limpiar Chart");
   
//+-----------------------------------------------------------------+     
//+--- Boton dibujar "Fibo Orange"

   CrearBoton("Boton1", 1730, 39, 44, 16,  clrBlack,  clrOrange, clrBlack,"ORBITRON BOLD",9,"Fibo");
   
//+-----------------------------------------------------------------+     
//+--- Boton dibujar "Fibo Red"

   CrearBoton("Boton2", 1775, 39, 45, 16,  clrWhite,  clrCrimson, clrBlack,"ORBITRON BOLD",9,"Fibo");
   
//+-----------------------------------------------------------------+     
//+--- Boton dibujar "Fibo Gold"

   CrearBoton("Boton3", 1821, 39, 44, 16,  clrBlack,  clrGold, clrBlack,"ORBITRON BOLD",9,"Fibo");

//+-----------------------------------------------------------------+     
//+--- Boton dibujar "Fibo Blue"

   CrearBoton("Boton4", 1730, 56, 44, 16,  clrWhite,  clrBlue, clrBlack,"ORBITRON BOLD",9,"Fibo");
   
//+-----------------------------------------------------------------+     
//+--- Boton dibujar "Fibo Green"

   CrearBoton("Boton5", 1775, 56, 45, 16,  clrWhite,  clrGreen, clrBlack,"ORBITRON BOLD",9,"Fibo");
   
//+-----------------------------------------------------------------+     
//+--- Boton dibujar "Fibo White"

   CrearBoton("Boton6", 1821, 56, 44, 16,  clrBlack,  clrWhiteSmoke, clrBlack,"ORBITRON BOLD",9,"Fibo");
      
//+-----------------------------------------------------------------+     
//---
   return(INIT_SUCCEEDED);
  }
  //+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   ObjectDelete("Boton");     //+--- Boton Limpiar chart de objetos "Limpiar Chart" 
   ObjectDelete("Boton1");    //+--- Boton1 Fibo de color naranja. "Fibo Orange" 
   ObjectDelete("Boton2");    //+--- Boton1 Fibo de color rojo. "Fibo Red"   
   ObjectDelete("Boton3");    //+--- Boton1 Fibo de color oro. "Fibo Gold"   
   ObjectDelete("Boton4");    //+--- Boton1 Fibo de color azul. "Fibo Blue"   
   ObjectDelete("Boton5");    //+--- Boton1 Fibo de color verde. "Fibo Green"   
   ObjectDelete("Boton6");    //+--- Boton1 Fibo de color blanco. "Fibo White"
   
   ObjectDelete("WorkZone");  //+--- Zona Fibo de color naranja. "Fibo orange"
   ObjectDelete("WorkZone1"); //+--- Zona Fibo de color rojo. "Fibo Red"
   ObjectDelete("WorkZone2"); //+--- Zona Fibo de color oro. "Fibo Gold"
   ObjectDelete("WorkZone3"); //+--- Zona Fibo de color azul. "Fibo Blue"
   ObjectDelete("WorkZone4"); //+--- Zona Fibo de color verde. "Fibo Green"
   ObjectDelete("WorkZone5"); //+--- Zona Fibo de color color blanco. "Fibo White"   
    
  } 
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
//------------------------------------------------------
{
   string clickedChartObject=sparam;
//------------------------------------------------------

//ID Boton
   if(clickedChartObject=="Boton")//+--- Boton  "Limpiar Chart"
     {
      ObjectsDeleteAll();
         CrearBoton("Boton", 1730, 22, 135, 16,  clrBlack,  clrChartreuse, clrBlack,"ORBITRON",9,"Limpiar Chart");
         CrearBoton("Boton1", 1730, 39, 44, 16,  clrBlack,  clrOrange, clrBlack,"ORBITRON BOLD",9,"Fibo");
         CrearBoton("Boton2", 1775, 39, 45, 16,  clrWhite,  clrCrimson, clrBlack,"ORBITRON BOLD",9,"Fibo");
         CrearBoton("Boton3", 1821, 39, 44, 16,  clrBlack,  clrGold, clrBlack,"ORBITRON BOLD",9,"Fibo");
         CrearBoton("Boton4", 1730, 56, 44, 16,  clrWhite,  clrBlue, clrBlack,"ORBITRON BOLD",9,"Fibo");
         CrearBoton("Boton5", 1775, 56, 45, 16,  clrWhite,  clrGreen, clrBlack,"ORBITRON BOLD",9,"Fibo");
         CrearBoton("Boton6", 1821, 56, 44, 16,  clrBlack,  clrWhiteSmoke, clrBlack,"ORBITRON BOLD",9,"Fibo");         
     }   
//------------------------------------------------------
//ID Boton1
   if(clickedChartObject=="Boton1")//+--- Boton  "Fibo Orange"
     {
     levelColor = clrTomato;
     Zcolor = clrPeachPuff;
     CreateFibo();
     
         CrearBoton("Boton1", 1730, 39, 44, 16,  clrBlack,  clrOrange, clrBlack,"ORBITRON BOLD",9,"Fibo");
   
     }
//------------------------------------------------------ 
//------------------------------------------------------
//ID Boton1
   if(clickedChartObject=="Boton2")//+--- Boton  "Fibo Red"
     {
     levelColor = clrCrimson;
     CreateFibo();
         CrearBoton("Boton2", 1775, 39, 45, 16,  clrWhite,  clrCrimson, clrBlack,"ORBITRON BOLD",9,"Fibo");
     }
//------------------------------------------------------ 
//------------------------------------------------------
//ID Boton1
   if(clickedChartObject=="Boton3")//+--- Boton  "Fibo Gold"
     {
     levelColor = clrGold;
     CreateFibo();
         CrearBoton("Boton3", 1821, 39, 44, 16,  clrBlack,  clrGold, clrBlack,"ORBITRON BOLD",9,"Fibo");
     }
//------------------------------------------------------ 
//------------------------------------------------------
//ID Boton1
   if(clickedChartObject=="Boton4")//+--- Boton "Fibo Blue"
     {
     levelColor = clrBlue;
     CreateFibo();
         CrearBoton("Boton4", 1730, 56, 44, 16,  clrWhite,  clrBlue, clrBlack,"ORBITRON BOLD",9,"Fibo");
     }
//------------------------------------------------------ 
//------------------------------------------------------
//ID Boton1
   if(clickedChartObject=="Boton5")//+--- Boton "Fibo Green"
     {
     levelColor = clrGreen;
     CreateFibo();
         CrearBoton("Boton5", 1775, 56, 45, 16,  clrWhite,  clrGreen, clrBlack,"ORBITRON BOLD",9,"Fibo");
     }
//------------------------------------------------------ 
//------------------------------------------------------
//ID Boton1
   if(clickedChartObject=="Boton6")//+--- Boton  "Fibo White"
     {
     levelColor = clrWhiteSmoke;
     CreateFibo();
         CrearBoton("Boton6", 1821, 56, 44, 16,  clrBlack,  clrWhiteSmoke, clrBlack,"ORBITRON BOLD",9,"Fibo");
     }
//------------------------------------------------------ 
  
 }
//===================================================================//

//+------------------------------------------------------------------+
//|  Crear retroceso de Fibonacci                                    |
//+------------------------------------------------------------------+

void CreateFibo()
  {
// --- comprobamos la corrección de los parámetros de entrada 
     int fibHigh = iHighest(Symbol(),Period(),MODE_HIGH,WindowFirstVisibleBar()-1,1);
     int fibLow  = iLowest(Symbol(),Period(),MODE_LOW,WindowFirstVisibleBar()-1,1);
     
     datetime highTime = Time[fibHigh];
     datetime lowTime  = Time[fibLow];
     
      if(fibHigh>fibLow){
      WindowRedraw();
      ObjectCreate(MPrefix+"FIBO_LAB",OBJ_FIBO,0,highTime,High[fibHigh],lowTime,Low[fibLow]);
      //levelColor = clrBlack;
      }
      else{
      WindowRedraw();
      ObjectCreate(MPrefix+"FIBO_LAB",OBJ_FIBO,0,lowTime,Low[fibLow],highTime,High[fibHigh]);
      levelColor = Fibo1Color;
      }
      fiboPrice1=ObjectGet(MPrefix+"FIBO_LAB",OBJPROP_PRICE1);
      fiboPrice2=ObjectGet(MPrefix+"FIBO_LAB",OBJPROP_PRICE2);
      
      fiboPriceDiff = fiboPrice2-fiboPrice1;
      fiboValue0 = DoubleToStr(fiboPrice2-fiboPriceDiff*FiboLevel1,Digits);
      fiboValue38 = DoubleToStr(fiboPrice2-fiboPriceDiff*FiboLevel2,Digits);
      fiboValue61 = DoubleToStr(fiboPrice2-fiboPriceDiff*FiboLevel3,Digits);
      fiboValue100 = DoubleToStr(fiboPrice2-fiboPriceDiff*FiboLevel4,Digits);
      fiboValue138 = DoubleToStr(fiboPrice2-fiboPriceDiff*FiboLevel5,Digits);
      fiboValue161 = DoubleToStr(fiboPrice2-fiboPriceDiff*FiboLevel6,Digits);     
      
      
     ObjectSet(MPrefix+"FIBO_LAB",OBJPROP_FIBOLEVELS,6);
     ObjectSet(MPrefix+"FIBO_LAB",OBJPROP_FIRSTLEVEL+0,FiboLevel1);
     ObjectSet(MPrefix+"FIBO_LAB",OBJPROP_FIRSTLEVEL+1,FiboLevel2);
     ObjectSet(MPrefix+"FIBO_LAB",OBJPROP_FIRSTLEVEL+2,FiboLevel3);
     ObjectSet(MPrefix+"FIBO_LAB",OBJPROP_FIRSTLEVEL+3,FiboLevel4);
     ObjectSet(MPrefix+"FIBO_LAB",OBJPROP_FIRSTLEVEL+4,FiboLevel5);
     ObjectSet(MPrefix+"FIBO_LAB",OBJPROP_FIRSTLEVEL+5,FiboLevel6);
    
     
     ObjectSet(MPrefix+"FIBO_LAB",OBJPROP_LEVELCOLOR,levelColor);
     ObjectSet(MPrefix+"FIBO_LAB",OBJPROP_LEVELWIDTH,1);
     ObjectSet(MPrefix+"FIBO_LAB",OBJPROP_LEVELSTYLE,STYLE_SOLID);
     
     ObjectSetFiboDescription( MPrefix+"FIBO_LAB", 0,fiboValue0+" --> "+DoubleToStr(FiboLevel1*100,1)+"%"); 
     ObjectSetFiboDescription( MPrefix+"FIBO_LAB", 1,fiboValue38+" --> "+DoubleToStr(FiboLevel2*100,1)+"%"); 
     ObjectSetFiboDescription( MPrefix+"FIBO_LAB", 2,fiboValue61+" --> "+DoubleToStr(FiboLevel3*100,1)+"%"); 
     ObjectSetFiboDescription( MPrefix+"FIBO_LAB", 3,fiboValue100+" --> "+DoubleToStr(FiboLevel4*100,1)+"%");
     ObjectSetFiboDescription( MPrefix+"FIBO_LAB", 4,fiboValue138+" --> "+DoubleToStr(FiboLevel5*100,1)+"%");
     ObjectSetFiboDescription( MPrefix+"FIBO_LAB", 5,fiboValue161+" --> "+DoubleToStr(FiboLevel6*100,1)+"%"); 
     
//+------------------------------------------------------------------------------------------------------+ 
// Creamos las zonas de trabajo. 

     datetime time1;
     datetime time2;
     double price1;
     double price2;
     
     StrToDouble (fiboValue0);
     StrToDouble (fiboValue38);
     StrToDouble (fiboValue61);
     StrToDouble (fiboValue100);
     StrToDouble (fiboValue19);
     StrToDouble (fiboValue119);
     StrToDouble (fiboValue89);     
    
    if (fiboValue0 > fiboValue38)
     {
     time1 = fibHigh;
     time2 = fibHigh + Time2D2(fibHigh, 2);
     price1 = fiboValue0; 
     price2 = fiboValue19;
     }
     else
     {
     time1 = fibHigh;
     time2 = fibHigh + Time2D2(fibHigh, 2);
     price1 = fiboValue0; 
     price2 = fiboValue19;     
     }
     
     WorkZone("WorkZone1", Zcolor, time1, price1, time2, price2);

     {
      return;
     }
//---
  }
  
//===================================================================//
//+------------------------------------------------------------------+
//| Función para crear botones                                       |
//+------------------------------------------------------------------+
  
void CrearBoton(string NrBoton,int Xdistance, int Ydistance, int Xsize, int Ysize, color TextColor, color ObjBGColor, color ObjBorderColor, string ObjFont,int ButtonFontSize, string ObjText)
  {
//------------------------------------------------------
   if(ObjectFind(0,NrBoton)==-1)
     {
      ObjectCreate(0,NrBoton,OBJ_BUTTON,0,0,0);
      ObjectSetInteger(0,NrBoton,OBJPROP_XDISTANCE,Xdistance);
      ObjectSetInteger(0,NrBoton,OBJPROP_YDISTANCE,Ydistance);
      ObjectSetInteger(0,NrBoton,OBJPROP_XSIZE,Xsize);
      ObjectSetInteger(0,NrBoton,OBJPROP_YSIZE,Ysize);
      ObjectSetInteger(0,NrBoton,OBJPROP_COLOR,TextColor);
      ObjectSetInteger(0,NrBoton,OBJPROP_BGCOLOR,ObjBGColor);
      ObjectSetInteger(0,NrBoton,OBJPROP_BORDER_COLOR,ObjBorderColor);
      ObjectSetString(0,NrBoton,OBJPROP_FONT,ObjFont);
      ObjectSetInteger(0,NrBoton,OBJPROP_FONTSIZE,ButtonFontSize);
      ObjectSetString(0,NrBoton,OBJPROP_TEXT,ObjText);
     }
//---
  }
//+------------------------------------------------------------------------------------------------------+  
//+------------------------------------------------------------------+
//| Función para crear areas de relleno (Rectangulos)                |
//+------------------------------------------------------------------+

void WorkZone(string name, color Zcolor,datetime time1,double price1,datetime time2,double price2)
  {
//------------------------------------------------------

   datetime Time2Day2 = Time2D2(TimeCurrent(),2);
   time2 = Time2Day2;
   if(ObjectFind(0,name)==-1)
   {  
    ObjectCreate(name,OBJ_RECTANGLE,0,Time[time1],price1,Time[time2],price2);
    ObjectSet(name,OBJPROP_COLOR,Zcolor);
   }
   
//---   
  }
//+------------------------------------------------------------------------------------------------------+ 
//+------------------------------------------------------------------+
//| Función para obtener el segundo punto del rectangulo             |
//+------------------------------------------------------------------+

   datetime Time2D2(datetime NuevaFecha, int Dias_a_Sumar)
// datetime Cambio_de_mes(datetime fecha_a_cambiar, int meses_a_sumar)                       
      {
         int Year2  =TimeYear(NuevaFecha);      // extraemos el año de la fecha
         int Month2 =TimeMonth(NuevaFecha);     // extraemos el mes de la fecha
         int Day2   =TimeDay(NuevaFecha);       // extraemos el día de la fecha

         Day2 = Day2+Dias_a_Sumar;              // sumamos al dia actual el número de dias que hemos pasado a la función
         
         if(Month2 >12){Month2 = Month2-12;Year2++;} // controla si tenemos que aumentar el año de la nueva fecha
         if(Day2 >30 && Month2!=11 && Month2!=4 && Month2!=6 && Month2!=9)Day2 =30; // controla los meses de 30 días si el día de la fecha es 31
         if(Day2==29 && Day2==2) // control de año bisiesto para posible fecha 29/02
            {
             if(MathMod(Year2,2)==0 && MathMod((Year2/2),3)==0 && MathMod(((Year2/2)/3),4)==0)Day2=28;
            }
          
      return(StrToTime(DoubleToStr(Year2,0)+"."+DoubleToStr(Month2,0)+"."
      +DoubleToStr(TimeDay(NuevaFecha),0)+" "+DoubleToStr(TimeHour(NuevaFecha),0)
      +":"+DoubleToStr(TimeMinute(NuevaFecha),0)));
      }
      /*
      datetime Time2Day2 = Time2D2(TimeCurrent(),2);
      */
      
//========================================================================================================================//