Download MetaTrader 5

Don't show buttons

To add comments, please log in or register
GrumpyDuckMan
597
GrumpyDuckMan  

Hello everyone,

How do I program button "HIDE" to toggle not visible/ visible any other buttons. I would like to have the ability to view chart without buttons showing up on chart, expect button "HIDE". 

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright " "
#property link      " "
#property version   "1.00"
#property strict

long chartid,Chart_ID;
string charts;
input int TIMEFRAME;
//-------------------------------------------------+
int OnInit()  {

   ChartSetInteger(Chart_ID,CHART_MODE,CHART_CANDLES);
   ChartSetInteger(Chart_ID,CHART_SHOW_GRID,false);
   ChartSetInteger(Chart_ID,CHART_AUTOSCROLL,true);
   ChartSetInteger(Chart_ID,CHART_SCALE,4);

   bool TimeFunction=ChartSetSymbolPeriod(chartid,charts,TIMEFRAME);

 //  ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
   string           InpName="Button";            // Button name
   ENUM_BASE_CORNER InpCorner=CORNER_LEFT_UPPER; // Chart corner for anchoring
   string           InpFont="Arial";             // Font
   int              InpFontSize=8;               // Font size
   color            InpColor=clrBlack;           // Text color
   color            InpBackColor=C'236,233,216'; // Background color
   color            InpBorderColor=clrNONE;      // 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

   int X_Button_size=100;
   int Y_Button_size=20;

   if(!ButtonCreate(0,"BUY",0,10,20,X_Button_size,Y_Button_size,InpCorner,"BUY",
      InpFont,InpFontSize,InpColor,InpBackColor,InpBorderColor,InpState,InpBack,
      InpSelection,InpHidden,InpZOrder)) {}
      
      if(!ButtonCreate(0,"SELL",0,110,20,X_Button_size,Y_Button_size,InpCorner,"SELL",
         InpFont,InpFontSize,InpColor,InpBackColor,InpBorderColor,InpState,InpBack,
         InpSelection,InpHidden,InpZOrder)) {}

         if(!ButtonCreate(0,"HISTORY",0,10,40,X_Button_size,Y_Button_size,InpCorner,"HISTORY",
            InpFont,InpFontSize,InpColor,InpBackColor,InpBorderColor,InpState,InpBack,
            InpSelection,InpHidden,InpZOrder)) {}
      
            if(!ButtonCreate(0,"MODIFY",0,110,40,X_Button_size,Y_Button_size,InpCorner,"MODIFY",
               InpFont,InpFontSize,InpColor,InpBackColor,InpBorderColor,InpState,InpBack,
               InpSelection,InpHidden,InpZOrder)) {}

               if(!ButtonCreate(0,"HIDE",0,10,60,X_Button_size,Y_Button_size,InpCorner,"HIDE",
                  InpFont,InpFontSize,InpColor,InpBackColor,InpBorderColor,InpState,InpBack,
                  InpSelection,InpHidden,InpZOrder)) {}
      
                  if(!ButtonCreate(0,"CANCEL",0,110,60,X_Button_size,Y_Button_size,InpCorner,"CANCEL",
                     InpFont,InpFontSize,InpColor,InpBackColor,InpBorderColor,InpState,InpBack,
                     InpSelection,InpHidden,InpZOrder)) {}

                     if(Chart_ID==CHARTEVENT_OBJECT_CLICK) 
                       {

                        ObjectSet("BUY",OBJPROP_XDISTANCE,20);     //
                        ObjectSet("BUY",OBJPROP_YDISTANCE,20);     //
                                                
                        ObjectSet("SELL",OBJPROP_XDISTANCE,110);   //
                        ObjectSet("SELL",OBJPROP_YDISTANCE,20);    //
                                                
                        ObjectSet("HISTORY",OBJPROP_XDISTANCE,20); //
                        ObjectSet("HISTORY",OBJPROP_YDISTANCE,40); //
                                                
                        ObjectSet("MODIFY",OBJPROP_XDISTANCE,110); //
                        ObjectSet("MODIFY",OBJPROP_YDISTANCE,40);  //
                                                
                        ObjectSet("CANCEL",OBJPROP_XDISTANCE,110); //
                        ObjectSet("CANCEL",OBJPROP_YDISTANCE,60);  //
                                                
                        ObjectSet("HIDE",OBJPROP_XDISTANCE,20);    //
                        ObjectSet("HIDE",OBJPROP_YDISTANCE,60);    //
                        ChartRedraw();
                      }
//------------------------------------------------------------------------------+
   return(INIT_SUCCEEDED);
 {
//-- 
 }
   return(INIT_SUCCEEDED); }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//-- 
  }
//+------------------------------------------------------------------+
void OnTick()
  {
//--  
  }
//+------------------------------------------------------------------+
void MarketTesting()
  {
 //--  
  }
//+------------------------------------------------------------------+

void TestReadFile()
  {
//--
  }
//+------------------------------------------------------------------+
void ModifyOrder()
  {
//--
  }
//--------------------------------------------------+ 
void buy()
  {
//--
  }
//+------------------------------------------------------------------+
void sell()
  {
//--
  }
//+------------------------------------------------------------------+
void CloseAllTrades()
  {
//--
  }
//+------------------------------------------------------------------+
void HIDE()
  {
//--
  }
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      if(sparam=="BUY")
        {
         buy();
         ObjectSetInteger(0,"BUY",OBJPROP_STATE,false); 
        }
      if(sparam=="SELL")
        {
         sell();
         ObjectSetInteger(0,"SELL",OBJPROP_STATE,false);
        }
      if(sparam=="HISTORY")
        {
         TestReadFile();
         ObjectSetInteger(0,"HISTORY",OBJPROP_STATE,false);
        }
      if(sparam=="MODIFY")
        {
         ModifyOrder();
         ObjectSetInteger(0,"MODIFY",OBJPROP_STATE,false);
        }
      if(sparam=="CANCEL")
        {
         CloseAllTrades();
         ObjectSetInteger(0,"CANCEL",OBJPROP_STATE,false);
        }
      if(sparam=="HIDE")
        {
         HIDE();
         ObjectSetInteger(0,"HIDE",OBJPROP_STATE,false);
        }
     }
  }
//+------------------------------------------------------------------+
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
  {
   if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0))
     {
      return(false); 
     }
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   return(true);
  }
To add comments, please log in or register