could you help me please?

 

Hi, I'm new to mql4. I'm learning. I would like to know if someone could help me with an indicator that I have! I would like to place a horizontal line at the 0 fibonacci level and when moving the horizontal line the fibonacci expands or recedes, thank you very much who can help me

#property copyright ""
#property link      ""

#property description "        "
#property description "()"

//+------------------------------------------------------------------+
//| Define the Variables to use.....                                 |
//+------------------------------------------------------------------+


//template code start1
 string             button_note2          = "------------------------------";
 ENUM_BASE_CORNER   btn_corner2            = CORNER_RIGHT_LOWER; // chart btn_corner2 for anchoring
 extern color       ColorFibo2             = clrBlack;
 string             btn_text2              = "1:10";
 string             btn_Font2              = "Arial";
 int                btn_FontSize2          = 10;                             //btn__font size
 color              btn_text_color2        = clrBlack;
 color              btn_background_color2  = clrLimeGreen;
color              btn_border_color2      = clrBlack;
 int                button_x2              = 40;                                     //btn__x
 int                button_y2              = 20;                                     //btn__y
int                btn_Width2             = 40;                                 //btn__width
 int                btn_Height2            = 20;                                //btn__height
 string             button_note3          = "------------------------------";
bool                      show_data2             = true;
string IndicatorName2, IndicatorObjPrefix2;
int WorkTime=0,Periods=0;
//template code end1

datetime drop_time;
   double drop_price;
   
   
//+------------------------------------------------------------------+
//template code start2
string GenerateIndicatorName2(const string target2)
{
   string name2 = target2;
   int try2 = 2;
   while (WindowFind(name2) != -1)
   {
      name2 = target2 + " #" + IntegerToString(try2++);
   }
   return name2;
}
//+------------------------------------------------------------------+
class VisibilityCotroller2
{
   string buttonID2;
   string visibilityId2;
   bool show_data2;
   bool recalc2;
public:
   void Init(string id2, string IndicatorName2, string caption2, int x2, int y2)
   {
      recalc2 = false;
      visibilityId2 = IndicatorName2 + "_visibility2";
      double val2;
      if (GlobalVariableGet(visibilityId2, val2))
         show_data2 = val2 != 0;
         
      buttonID2 = id2;
      ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, 1);
      createButton2(buttonID2, caption2, btn_Width2, btn_Height2, btn_Font2, btn_FontSize2, btn_background_color2, btn_border_color2, btn_text_color2);
      ObjectSetInteger(0,buttonID2,OBJPROP_YDISTANCE, button_y2);
      ObjectSetInteger(0,buttonID2,OBJPROP_XDISTANCE, button_x2);

   }
//+------------------------------------------------------------------+
   void DeInit()
   {
      ObjectDelete(ChartID(), buttonID2);
      ObjectDelete("FibNode#1");
      ObjectDelete("FiboDn2");
      ObjectDelete("FiboIn2");
   }
//+------------------------------------------------------------------+
   bool HandleButtonClicks2()
   {
      if (ObjectGetInteger(0, buttonID2, OBJPROP_STATE))
      {
         ObjectSetInteger(0, buttonID2, OBJPROP_STATE, false);
         show_data2 = !show_data2;
         GlobalVariableSet(visibilityId2, show_data2 ? 1.0 : 0.0);
         recalc2 = true;
         return true;
      }
      return false;
   }
//+------------------------------------------------------------------+
   bool IsRecalcNeeded2()
   {
      return recalc2;
   }
//+------------------------------------------------------------------+
   void ResetRecalc2()
   {
      recalc2 = false;
   }
//+------------------------------------------------------------------+
   bool IsVisible2()
   {
      return show_data2;
   }
//+------------------------------------------------------------------+
private:
   void createButton2(string buttonID2,string buttonText2,int width2,int height2,string font2,int fontSize2,color bgColor2,color borderColor2,color txtColor2)
   {
      ObjectDelete    (0,buttonID2);
      ObjectCreate    (0,buttonID2,OBJ_BUTTON,0,0,0);
      ObjectSetInteger(0,buttonID2,OBJPROP_COLOR,txtColor2);
      ObjectSetInteger(0,buttonID2,OBJPROP_BGCOLOR,bgColor2);
      ObjectSetInteger(0,buttonID2,OBJPROP_BORDER_COLOR,borderColor2);
      ObjectSetInteger(0,buttonID2,OBJPROP_BORDER_TYPE,BORDER_RAISED);
      ObjectSetInteger(0,buttonID2,OBJPROP_XSIZE,width2);
      ObjectSetInteger(0,buttonID2,OBJPROP_YSIZE,height2);
      ObjectSetString (0,buttonID2,OBJPROP_FONT,font2);
      ObjectSetString (0,buttonID2,OBJPROP_TEXT,buttonText2);
      ObjectSetInteger(0,buttonID2,OBJPROP_FONTSIZE,fontSize2);
      ObjectSetInteger(0,buttonID2,OBJPROP_SELECTABLE,0);
      ObjectSetInteger(0,buttonID2,OBJPROP_CORNER,btn_corner2);
      ObjectSetInteger(0,buttonID2,OBJPROP_HIDDEN,1);
   }
};
VisibilityCotroller2 visibility2;
//+------------------------------------------------------------------+
int init()
  {
   IndicatorName2 = GenerateIndicatorName2("Fibo2");
   IndicatorObjPrefix2 = "__" + IndicatorName2 + "__";
   IndicatorShortName(IndicatorName2);
   IndicatorDigits(Digits);
   visibility2.Init("show_hide_Fibo2", IndicatorName2, btn_text2, button_x2, button_y2);
//DON'T put the init function here
   return 0;
};
//+------------------------------------------------------------------+
int deinit()  
  {
   visibility2.DeInit();
    ObjectsDeleteAll(ChartID(), IndicatorObjPrefix2);

//PUT deinit () here
    ObjectDelete("FibNode#1");
    ObjectDelete("FiboDn2");
    ObjectDelete("FiboIn2");
   return(0);
  }
//+------------------------------------------------------------------+
void OnChartEvent(const int id2,
                  const long &lparam2,
                  const double &dparam2,
                  const string &sparam2)
{
   if (visibility2.HandleButtonClicks2())
      start();
}
//+------------------------------------------------------------------+
//template end2
int DrawFibo()
{  datetime drop_time=WindowTimeOnDropped();
   double drop_price=WindowPriceOnDropped();
   
   if (drop_time>0)
   {} else {drop_time=TimeCurrent(); drop_price=Bid;}
   
        if(ObjectFind("FibNode#1") == -1)
                ObjectCreate("FibNode#1",OBJ_FIBO,0,drop_time,drop_price,drop_time+1,drop_price-(Point*30));
        
                ObjectSet("FibNode#1",OBJPROP_LEVELCOLOR,ColorFibo2);
   //ObjectSet("FibNode#1",OBJPROP_LEVELSTYLE,STYLE_DASH);
   ObjectSet("FibNode#1",OBJPROP_LEVELWIDTH,1);
   ObjectSet("FibNode#1",OBJPROP_COLOR, ColorFibo2);
   ObjectSet("FibNode#1",OBJPROP_STYLE ,STYLE_SOLID);
   ObjectSet("FibNode#1",OBJPROP_RAY,False);
   
        
   
   ObjectSet("FibNode#1",OBJPROP_FIBOLEVELS,12);
    ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+0,1); // entry price ... 1
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+1,-0.0); // SL R ... 0
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+2,2.0); // TP 0.5R 
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+3,3.0); // TP 1.0R 
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+4,4.0); // TP 1.5R 
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+5,5.0); // TP 1.5R 
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+6,6.0); // TP 1.5R
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+7,7.0); // TP 1.5R
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+8,8.0); // TP 1.5R
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+9,9.0); // TP 1.5R
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+10,10.0); // TP 1.5R
   ObjectSet("FibNode#1",OBJPROP_FIRSTLEVEL+11,11.0); // TP 1.5R

         ObjectSetFiboDescription( "FibNode#1", 0,"Entry");
   ObjectSetFiboDescription( "FibNode#1", 1,"SL");
   ObjectSetFiboDescription( "FibNode#1", 2,"1:1");
   ObjectSetFiboDescription( "FibNode#1", 3,"1:2");
   ObjectSetFiboDescription( "FibNode#1", 4,"1:3");
   ObjectSetFiboDescription( "FibNode#1", 5,"1:4");
   ObjectSetFiboDescription( "FibNode#1", 6,"1:5");
   ObjectSetFiboDescription( "FibNode#1", 7,"1:6");
   ObjectSetFiboDescription( "FibNode#1", 8,"1:7");
   ObjectSetFiboDescription( "FibNode#1", 9,"1:8");
   ObjectSetFiboDescription( "FibNode#1",10,"1:9");
   ObjectSetFiboDescription( "FibNode#1",11,"1:10");
      
   return(0);
}

//+------------------------------------------------------------------+
int start()
{
   
      
  
   
//template start3
   visibility2.HandleButtonClicks2();
   visibility2.ResetRecalc2();
   
   if (visibility2.IsVisible2())
   {
//template end3



//template start4
      if( (WorkTime != Time[0]) || (Periods != Period()) ) 
      {
         if (show_data2)
         {
            DrawFibo();
         }
         else
         {
              ObjectDelete("FibNode#1");
              ObjectDelete("FiboDn2");
              ObjectDelete("FiboIn2");
         }
      }
   }
   else
   {
      ObjectDelete("FibNode#1");
      ObjectDelete("FiboDn2");
      ObjectDelete("FiboIn2");
   }
//template end4  
   return(0);
}
//+------------------------------------------------------------------+

 
Sabrina Pepe:

Hi, I'm new to mql4. I'm learning. I would like to know if someone could help me with an indicator that I have! I would like to place a horizontal line at the 0 fibonacci level and when moving the horizontal line the fibonacci expands or recedes, thank you very much who can help me

There's a lot that you're asking for, but it comes down to using the ChartEvent CHARTEVENT_OBJECT_DRAG.

When the event is fired, check the sparam of OnChartEvent() to make sure it matches the name of the HLine . If it does, then get the HLine's OBJPROP_PRICE value and set it to the Fibo's OBJPROP_PRICE1 or OBJPROP_PRICE2 value, whichever is the 0 level of your Fibo.

Types of Chart Events - Chart Constants - Constants, Enumerations and Structures - MQL4 Reference
Types of Chart Events - Chart Constants - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Types of Chart Events - Chart Constants - Constants, Enumerations and Structures - MQL4 Reference
 
Alexander Martinez #:

There's a lot that you're asking for, but it comes down to using the ChartEvent CHARTEVENT_OBJECT_DRAG.

When the event is fired, check the sparam of OnChartEvent() to make sure it matches the name of the HLine . If it does, then get the HLine's OBJPROP_PRICE value and set it to the Fibo's OBJPROP_PRICE1 or OBJPROP_PRICE2 value, whichever is the 0 level of your Fibo.


I'm going to try thank you very much
 
Sabrina Pepe #:

I'm going to try thank you very much

No problem!

You might also want to do the same for CHARTEVENT_OBJECT_CHANGE. This event is fired whenever a user edits the object via the properties dialog box.

Reason: