How to create button to go to website

 
hello. I have coded some example EA. I want it to able to go to www.google.com when I click on button. anyone if could please help me. thanks.

#property link      ""
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
//---
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
//Basic button settings
   string           InpName          = "TradeButton";        // Button name
   ENUM_BASE_CORNER InpCorner        = CORNER_LEFT_UPPER;    // Chart corner for anchoring
   string           InpFont          = "Arial";              // Font
   int              InpFontSize      = 8;                    // Font size
   color            InpColor         = clrWhite;             // Text color
   color            InpBackColor     = clrBlue;              // Background color
   color            InpBorderColor   = clrRed;               // Border color
   bool             InpState         = false;                // Pressed/Released
   bool             InpBack          = false;                // Background object
   bool             InpSelection     = false;                // Highlight to move
   bool             InpHidden        = true;                 // Hidden in the object list
   long             InpZOrder        = 0;                    // Priority for mouse click
//--- set the button coordinates and its size
   int x=(int)(800);
//--- set the move button coordinates and its size
   int y=(int)(200);
//--- create the button
   if(!ButtonCreate(0,"link",0,x,y,30,10,InpCorner,"www.google.com",InpFont,6,
      InpColor,InpBackColor,InpBorderColor,InpState,InpBack,InpSelection,InpHidden,InpZOrder))
   {

   }
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- reset the error value
   ResetLastError();
//--- delete the button
   if(!ObjectDelete(ChartID(), "link"))
   {
      Print(__FUNCTION__, ": failed to delete CloseAll! Error code = ", GetLastError());
   }
//---
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
   
//---
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
//---
   if(id == CHARTEVENT_OBJECT_CLICK)
   {
      if(ObjectGetInteger(ChartID(), "link", OBJPROP_STATE))
      {
         // go to www.google.com
      }
   }
}
//+------------------------------------------------------------------+
//| 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_LEFT_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);
//--- set button state
   ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);
//--- 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);
}
//+------------------------------------------------------------------+
 
That's my question too.
 
Revazi Tchitanava: hello. I have coded some example EA. I want it to able to go to www.google.com when I click on button. anyone if could please help me. thanks.
To have a button open a URL in the browser you would have to invoke a DLL call to the Windows API. It is not possible in pure MQL code.
 
#property version   "1.00"
#import "shell32.dll" 
int ShellExecuteW(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd); 
#import
int OnInit()
  {
  //exampel
  ObjectsDeleteAll(ChartID(),"BTN_");
  /*
  Create Le button
  */
  HS_Create_Btn(ChartID(),0,"BTN_LINK",200,20,10,10,"Arial",14,clrRoyalBlue,clrMidnightBlue,BORDER_FLAT,clrGoldenrod,ALIGN_CENTER,"Click Here",false,false);   
  /* now you must link the button to the manage link function , go to the On Chart Event Section */
  return(INIT_SUCCEEDED);
  }
  
void Manage_Link(string the_link,string text_alt)
{
if(!IsDllsAllowed()) Alert(text_alt+"\n"+the_link);
if(IsDllsAllowed()==true) ShellExecuteW(NULL,"open",the_link,"","",5);
}
bool IsDllsAllowed()
{
bool iz=(bool)MQLInfoInteger(MQL_DLLS_ALLOWED);
return(iz);
}
//CREATE BTN OBJECT
  void HS_Create_Btn(long cid,
                     int subw,
                     string name,
                     int sx,
                     int sy,
                     int px,
                     int py,
                     string font,
                     int fontsize,
                     color bck_col,
                     color brd_col,
                     ENUM_BORDER_TYPE brd_type,
                     color txt_col,
                     ENUM_ALIGN_MODE align,
                     string text,
                     bool selectable,
                     bool back)  
  {
  bool obji=ObjectCreate(cid,name,OBJ_BUTTON,subw,0,0);
  if(obji)
    {
    ObjectSetString(0,name,OBJPROP_FONT,font);
    ObjectSetInteger(0,name,OBJPROP_ALIGN,align);
    ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize);
    ObjectSetInteger(0,name,OBJPROP_XSIZE,sx);
    ObjectSetInteger(0,name,OBJPROP_YSIZE,sy);
    ObjectSetInteger(0,name,OBJPROP_XDISTANCE,px);
    ObjectSetInteger(0,name,OBJPROP_YDISTANCE,py);
    ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bck_col);
    ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,brd_col);
    ObjectSetInteger(0,name,OBJPROP_COLOR,txt_col);
    ObjectSetInteger(0,name,OBJPROP_BORDER_TYPE,brd_type);
    ObjectSetInteger(0,name,OBJPROP_SELECTABLE,selectable);
    ObjectSetInteger(0,name,OBJPROP_BACK,back);
    ObjectSetString(0,name,OBJPROP_TEXT,text);
    }
  ChartRedraw(0);
  }                   
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
  /*
  if an object is clicked and that object is the link 
  */
  if(id==CHARTEVENT_OBJECT_CLICK&&sparam=="BTN_LINK"){
  /* we send them to the link , or , in case the user has their dlls off we display a message 
     -you could get creative here and display a QR code as an alternative  
  */
  Manage_Link("https:\\www.google.com","Visit Google.com to buy the best pants!");
  } 
  }

Try this 

 
Fernando Carreiro #:
To have a button open a URL in the browser you would have to invoke a DLL call to the Windows API. It is not possible in pure MQL code.

Its not letting me run the ea without the dll allowed , what have i missed ? did they change something ? 

 
Lorentzos Roussos #: Its not letting me run the ea without the dll allowed , what have i missed ? did they change something ? 

DLL permission has to be enable globally in the "Options" as well as in the EA's launch properties (if I remember correctly).

 
Fernando Carreiro #:

DLL permission has to be enable globally in the "Options" as well as in the EA's launch properties (if I remember correctly).

Sorry , I meant when i uncheck the dll on the ea properties before starting the OK button vanishes .  

 
Lorentzos Roussos #: Sorry , I meant when i uncheck the dll on the ea properties before starting the OK button vanishes .  

I tried it myself and see what you mean. MetaQuotes may have changed the functionality to prevent loading it at all if it has DLL imports and you don't enable it. Since it has been a long time since I used DLLs, I don't know when this happened.

EDIT: This would mean that checking for DLL allowed in the code, will be of no use ...

EDIT2: ... unless the check MQL_DLLS_ALLOWED refers to the global permission only, when one enables the DLL for the EA but not for the global Options.

 
Fernando Carreiro #:

I tried it myself and see what you mean. MetaQuotes may have changed the functionality to prevent loading it at all if it has DLL imports and you don't enable it. Since it has been a long time since I used DLLs, I don't know when this happened.

EDIT: This would mean that checking for DLL allowed in the code, will be of no use, unless the check MQL_DLLS_ALLOWED refers to the global permission instead.

So a hesitant user justifiably won't run the EA if MQ is not allowing them to continue without dlls . (aside from the confusion it will cause)

(rofl emoji)

Maybe they attempted to simplify things so instead of the coder informing the user to enable dlls the program does not run at all without dlls.

The user will of course just abandon the program and never start it. 

 
It is this way ever since i started using MT5 mid 2017.