Download MetaTrader 5

Is it possible to draw buttons on chart with the new MT4 update - page 2

To add comments, please log in or register
SemperAugustus
20
SemperAugustus  
Sorry, got things messed up a bit.
Simon Gniadkowski
Moderator
18025
Simon Gniadkowski  
SemperAugustus:
Sorry, got things messed up a bit.

I guessed you had
whroeder1
15901
whroeder1  
SemperAugustus: What i need is the time of the most left candle that is actually visible.
Don't double post
Tradeing Trader
567
Tradeing Trader  

This is my current Expert Advisor, but i dont know how to do it.

What i want is for example that the EA print a message when i click on the button.


#property strict
//--- description
#property description "Script creates the button on the chart."
//--- display window of the input parameters during the script's launch


input string           InpName="Button";            // Button name
input ENUM_BASE_CORNER InpCorner=CORNER_RIGHT_UPPER;// Chart corner for anchoring
input string           InpFont="Arial";             // Font
input int              InpFontSize=14;              // Font size
input color            InpColor=clrBlack;           // Text color
input color            InpBackColor=C'236,233,216'; // Background color
input color            InpBorderColor=clrNONE;      // Border color
input bool             InpState=false;              // Pressed/Released
input bool             InpBack=false;               // Background object
input bool             InpSelection=false;          // Highlight to move
input bool             InpHidden=true;              // Hidden in the object list
input long             InpZOrder=0;                 // Priority for mouse click
//+------------------------------------------------------------------+
//| Create the button                                                |
//+------------------------------------------------------------------+
bool ButtonCreate(const long              chart_ID=0,               // chart's ID
                  const string            name="Button",            // button name
                  const int               sub_window=0,             // subwindow index
                  const int               x=0,                      // X coordinate
                  const int               y=0,                      // Y coordinate
                  const int               width=50,                 // button width
                  const int               height=18,                // button height
                  const ENUM_BASE_CORNER  corner=CORNER_RIGHT_UPPER,// chart corner for anchoring
                  const string            text="Button",            // text
                  const string            font="Arial",             // font
                  const int               font_size=10,             // font size
                  const color             clr=clrBlack,             // text color
                  const color             back_clr=C'236,233,216',  // background color
                  const color             border_clr=clrNONE,       // border color
                  const bool              state=false,              // pressed/released
                  const bool              back=false,               // in the background
                  const bool              selection=false,          // highlight to move
                  const bool              hidden=true,              // hidden in the object list
                  const long              z_order=0)                // priority for mouse click
  {
//--- reset the error value
   ResetLastError();
//--- create the button
   if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0))
     {
      Print(__FUNCTION__,
            ": failed to create the button! Error code = ",GetLastError());
      return(false);
     }
//--- set button coordinates
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set button size
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- set the chart's corner, relative to which point coordinates are defined
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set the text
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text font
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font size
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set text color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set background color
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
//--- set border color
   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the button by mouse
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- 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);
  }

 

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   ObjectDelete(0,"button");
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int lenght = 100;
   int height = 20;
   
//--- create the button
   if(ObjectFind(InpName)<0)
   {
   if(!ButtonCreate(0,InpName,0,110,10,lenght,height,InpCorner,"Press",InpFont,InpFontSize,InpColor,InpBackColor,InpBorderColor,InpState,InpBack,InpSelection,InpHidden,InpZOrder))
     {
      return;
     }
   }
//--- redraw the chart
   ChartRedraw();
//---
  }


//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // Event identifier  
                  const long& lparam,   // Event parameter of long type
                  const double& dparam, // Event parameter of double type
                  const string& sparam) // Event parameter of string type
  {
//--- the left mouse button has been pressed on the chart
   if(id==CHARTEVENT_CLICK)
     {
      Print("The coordinates of the mouse click on the chart are: x = ",lparam,"  y = ",dparam);
     }
//--- the mouse has been clicked on the graphic object
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      Print("The mouse has been clicked on the object with name '"+sparam+"'");
     }
  }
   
qjol
3243
qjol  
i dont understand what u want, it's printing !
Tradeing Trader
567
Tradeing Trader  
Where is it printing? I am looking into the Journal tab when i make backtest and i dont see that the print there somethink when i click into the chart or on the button.
Simon Gniadkowski
Moderator
18025
Simon Gniadkowski  
PlanandTrade:
Where is it printing? I am looking into the Journal tab when i make backtest and i dont see that the print there somethink when i click into the chart or on the button.
Perhaps buttons don't work in the Strategy Tester, try on a live chart . . . certainly in MT5 Buttons didn't work in the Strategy Tester, I haven't tested this recently.
Tradeing Trader
567
Tradeing Trader  
Thank you for the info, i would not have find the reason why it dont work in the strategy tester without your info. I have try it now on a live chart and here it does work.
Vladislav Andruschenko
103921
Vladislav Andruschenko  

for example

<Picture removed by moderator>

Alain Verleyen
Moderator
33261
Alain Verleyen  
Vladon:


Hello,

Please note the we are not allowed to advertise on this forum. From the rules :

Posting of advertising messages, spamming and flooding are forbidden.

So, please don't try to advertise, even indirectly. Thank you.

12
To add comments, please log in or register