Unable to customize graphical Fibo levels in MQL4

 

Hello guys,


I am struggling for many days (actually I left it on the side for one year but now I would like to make it work) to customize Fibo levels : color, width, style as well as RAY_RIGHT property.

Unfortunately my code doesn't work even after have read the documentation carefully and retried many many times.

Levels customization is working as well as customized text but colors, widths and styles are all the same, and RAY_RIGHT is enabled by default even when set to false.

So I came back to the documentation, took the code (that actually is not being a complete working example) and found that MQL4 doc is not working as expected either.

I have posted the code as attached file but I can't believe Fibo is buggy but I can not find any working example while browsing the net.

I could leave the code as is but I really would like to be able to customize every aspect of my Fibo object.


Thx in advance.

 


:

Hi Gandalf!


I think the code is not attached?

 
withoutprejudice #:

Hi Gandalf!


I think the code is not attached?

Hi Withoutprejudice,


thx for your reply.

I have put it in the <code> section, however, let me post again in the <code> section.


Regards





//+------------------------------------------------------------------+
//|                                                    test_fibo.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//--- input parameters of the script 
input string          InpName="FiboLevels";      // Object name 
input int             InpDate1=10;               // 1 st point's date, % 
input int             InpPrice1=65;              // 1 st point's price, % 
input int             InpDate2=90;               // 2 nd point's date, % 
input int             InpPrice2=85;              // 2 nd point's price, % 
input color           InpColor=clrRed;           // Object color 
input ENUM_LINE_STYLE InpStyle=STYLE_DASHDOTDOT; // Line style 
input int             InpWidth=1;                // Line width 
input bool            InpBack=false;             // Background object 
input bool            InpSelection=true;         // Highlight to move 
input bool            InpRayRight=false;         // Object's continuation to the right 
input bool            InpHidden=true;            // Hidden in the object list 
input long            InpZOrder=0;               // Priority for mouse click 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   datetime date1 = StringToTime( "2021.11.21 02:40" );
   datetime date2 = StringToTime( "2021.11.25 19:40" );
   double price1 = 1.12930;
   double price2 = 1.13510;    
   double val[8] = { 0.0, 0.236, 0.382, 0.5, 0.618, 1, 1.618, 2.618 } ;
   color col[8] = { clrLavender, clrYellow, clrBlueViolet, clrMagenta, clrMaroon, clrAliceBlue, clrAquamarine, clrAzure };
   ENUM_LINE_STYLE sty[8] = { STYLE_DASH, STYLE_DASHDOT, STYLE_DASHDOT, STYLE_DASHDOT, STYLE_DASHDOT, STYLE_DASHDOTDOT, STYLE_DASHDOT, STYLE_DASHDOT };
   int wid[8] = { 4, 1, 1, 1, 1, 1, 1, 4 };
   FiboLevelsCreate(0, "FiboLevels", 0, date2, price2, date1, price1, clrRed, STYLE_DASHDOT, 3, false, true, true, false);
   FiboLevelsSet(8, val, col, sty, wid);   
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   ObjectDelete( 0, "FiboLevels" );
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
bool FiboLevelsCreate(const long            chart_ID=0,        // chart's ID 
                      const string          name="FiboLevels", // object name 
                      const int             sub_window=0,      // subwindow index  
                      datetime              time1=0,           // first point time 
                      double                price1=0,          // first point price 
                      datetime              time2=0,           // second point time 
                      double                price2=0,          // second point price 
                      const color           clr=clrRed,        // object color 
                      const ENUM_LINE_STYLE style=STYLE_DASH, // object line style 
                      const int             width=1,           // object line width 
                      const bool            back=false,        // in the background 
                      const bool            selection=true,    // highlight to move 
                      const bool            ray_right=false,   // object's continuation to the right 
                      const bool            hidden=true,       // hidden in the object list 
                      const long            z_order=0)         // priority for mouse click 
  { 
//--- set anchor points' coordinates if they are not set 
//   ChangeFiboLevelsEmptyPoints(time1,price1,time2,price2); 
//--- reset the error value 
   ResetLastError(); 
//--- Create Fibonacci Retracement by the given coordinates 
   if(!ObjectCreate(chart_ID,name,OBJ_FIBO,sub_window,time1,price1,time2,price2)) 
     { 
      Print(__FUNCTION__, 
            ": failed to create \"Fibonacci Retracement\"! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- set color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- set line style 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
//--- set line width 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of highlighting the channel for moving 
//--- when creating a graphical object using ObjectCreate function, the object cannot be 
//--- highlighted and moved by default. Inside this method, selection parameter 
//--- is true by default making it possible to highlight and move the object 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- enable (true) or disable (false) the mode of continuation of the object's display to the right 
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  } 
//+------------------------------------------------------------------+
bool FiboLevelsSet(int             levels,            // number of level lines 
                   double          &values[],         // values of level lines 
                   color           &colors[],         // color of level lines 
                   ENUM_LINE_STYLE &styles[],         // style of level lines 
                   int             &widths[],         // width of level lines 
                   const long      chart_ID=0,        // chart's ID 
                   const string    name="FiboLevels") // object name 
  { 
//--- check array sizes 
   if(levels!=ArraySize(colors) || levels!=ArraySize(styles) || 
      levels!=ArraySize(widths) || levels!=ArraySize(widths)) 
     { 
      Print(__FUNCTION__,": array length does not correspond to the number of levels, error!"); 
      return(false); 
     } 
//--- set the number of levels 
   ObjectSetInteger(chart_ID,name,OBJPROP_LEVELS,levels); 
//--- set the properties of levels in the loop 
   for(int i=0;i<levels;i++) 
     { 
      //--- level value 
      ResetLastError();
      ObjectSetDouble(chart_ID,name,OBJPROP_LEVELVALUE,i,values[i]); 
      Alert("Last error : ", GetLastError());
      //--- level color  
      ResetLastError();      
      ObjectSetInteger(chart_ID,name,OBJPROP_LEVELCOLOR,i,colors[i]); 
      Alert("Last error : ", GetLastError());      
      //--- level style 
      ResetLastError();      
      ObjectSetInteger(chart_ID,name,OBJPROP_LEVELSTYLE,i,styles[i]); 
      Alert("Last error : ", GetLastError());      
      //--- level width 
      ResetLastError();      
      ObjectSetInteger(chart_ID,name,OBJPROP_LEVELWIDTH,i,widths[i]); 
      Alert("Last error : ", GetLastError());      
      //--- level description 
      ObjectSetString(chart_ID,name,OBJPROP_LEVELTEXT,i,DoubleToString(100*values[i],1)); 
     } 
//--- successful execution 
   return(true); 
  } 
 
gandalfitexpert #:


is there a code to actually create the first object with the input parameters?

What error messages are you getting when you run the code?

 
withoutprejudice #:

is there a code to actually create the first object with the input parameters?

What error messages are you getting when you run the code?

The code to create the object is in the OnInit() function.

I don't get any error message unfortunately (I have tried to track all errors function by function - ObjectSetInteger).

 
gandalfitexpert #:

The code to create the object is in the OnInit() function.

I don't get any error message unfortunately (I have tried to track all errors function by function - ObjectSetInteger).

I am wondering if it has to do with the initial price values? When I was testing the code this was the issue, the prices were not present on the chart that I ran the EA on. Then when i adjusted those price values the object appeared.
 
withoutprejudice #:
I am wondering if it has to do with the initial price values? When I was testing the code this was the issue, the prices were not present on the chart that I ran the EA on. Then when i adjusted those price values the object appeared.

Hi Withoutprejudice,

I don't think so, actually I was doing the test on EURUSD and both prices were in the range.

BTW did you identify the same issues as I did regarding Fibo object customization ? 

Anyway thx for your help.

 
gandalfitexpert #:

Hi Withoutprejudice,

I don't think so, actually I was doing the test on EURUSD and both prices were in the range.

BTW did you identify the same issues as I did regarding Fibo object customization ? 

Anyway thx for your help.

for me the issue was that the object was not appearing at all. When I adjusted the initial price values i saw a fibonaci with a red main line and orange level lines. Apologies I wish i could help more, if I will look at it more when i am coding and hopefully we can solve
 
withoutprejudice #:
for me the issue was that the object was not appearing at all. When I adjusted the initial price values i saw a fibonaci with a red main line and orange level lines. Apologies I wish i could help more, if I will look at it more when i am coding and hopefully we can solve

Hi Withoutprejudice,


I already thank you for your feedback.

If you can go further and identify the issue that prevents customization, just let me know :-)


Regards 

Reason: