Fibo drawing problems

Hi!

I’d like to draw a fibonacci without click mt4 fibo button. It needs to my expert advisor.

I’d like to use a simple button to start drawing. (Button code not good, but I think I can write to work good.) So, I need: click on the button, than click and HOLD on chart to start drawing fibo (fibo appear on the chart, and I release left button. This is all I need.

Please help me!

#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#define BUTTON_NAME "Button"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
bool   MouseDown = false, MouseClicked = false;

int OnInit()
  {
//---
  string name= "Button";
  ObjectCreate(0,name,OBJ_BUTTON,0,0,0);
  ObjectSetInteger(0,name,OBJPROP_XSIZE,250);
  ObjectSetInteger(0,name,OBJPROP_YSIZE,50);
  ObjectSetInteger(0,name,OBJPROP_XDISTANCE,10);
  ObjectSetInteger(0,name,OBJPROP_XDISTANCE,20);
  ObjectSetInteger(0,name,OBJPROP_COLOR,clrAliceBlue);
  ObjectSetInteger(0,name,OBJPROP_BGCOLOR,clrTomato);
  
  ObjectSetString(0,name,OBJPROP_TEXT,"Start drawing Fibo"); 
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
  ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,1);
  }
  
void OnChartEvent(const int id, 
                  const long& lparam, 
                  const double& dparam, 
                  const string& sparam){
  
  if(id==CHARTEVENT_MOUSE_MOVE ) {
      if( MouseLeftButtonState((uint)sparam) == "DN" && !MouseDown){
      MouseDown = true;
      MouseClicked = false;
      datetime _Time;
      double _Price;
      int _window=0;
      ChartXYToTimePrice(0,int (lparam),int (dparam),_window,_Time,_Price);
      ObjectCreate(0,"Fibo2",OBJ_FIBO,0,_Time,_Price);
      ObjectSet("Fibo2",OBJPROP_FIBOLEVELS,3);
      ObjectSet("Fibo2",OBJPROP_FIRSTLEVEL+0,0.0);
      ObjectSet("Fibo2",OBJPROP_FIRSTLEVEL+1,-0.382);
      ObjectSet("Fibo2",OBJPROP_FIRSTLEVEL+2,2.618);
     
      ObjectSetFiboDescription( "Fibo2", 0," 0.0%"); 
      ObjectSetFiboDescription( "Fibo2", 1," -38.2"); 
      ObjectSetFiboDescription( "Fibo2", 2," 261.8");
      }
      
      if( MouseLeftButtonState((uint)sparam) == "UP" && MouseDown ) {
         MouseClicked = true;
         MouseDown = false;
         datetime _Time2;
         double _Price2;
         int _window2=0;
         ChartXYToTimePrice(0,int (lparam),int (dparam),_window2,_Time2,_Price2);
         ObjectSet("Fibo2",OBJPROP_TIME2,_Time2);
         ObjectSet("Fibo2",OBJPROP_PRICE2,_Price2);
           
      }   
   
  }

}  
string MouseLeftButtonState(uint state) {
   string res;
   res+=(((state& 1)== 1)?"DN":"UP");   // mouse left
   return(res);
}
1 Like