Download MetaTrader 5

problem with rectangle label - page 2

To add comments, please log in or register
metbright
101
metbright  

OK, I will show some code.

I think problem is rectangle label because I try to delete it then I can click the button.


These are some code.

#property  indicator_separate_window

bool button_sy;

int OnInit() {

   IndicatorShortName("sample");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
      
      for(int i=ObjectsTotal() - 1; i >= 0; i--){
         string name = ObjectName(i);
         if (StringFind(name, "mm") >= 0) ObjectDelete(name);

      }

      createBG("mm_bg00", 0, 0, 1500, 400, clrBlack, clrBlack, CORNER_LEFT_UPPER, STYLE_SOLID, 0, false, false, false, 0);
      
      createLabel("mm_button05", 1220, 2, CORNER_LEFT_UPPER, "จ", "Wingdings", 13, 0.0, ANCHOR_LEFT_UPPER, clrWhite, false, false, false, 10);
      if(button_sy) { 
         createLabel("mm_button05-1", 1223, 2, CORNER_LEFT_UPPER, "P", "Wingdings 2", 13, 0.0, ANCHOR_LEFT_UPPER, clrWhite, false, false, false, 10); 
      }
      
      

      
   return(rates_total);
  }
      
      
//+------------------------------------------------------------------+
//| Create BG                                                        |
//+------------------------------------------------------------------+
bool createBG( string            object_name,
              // ENUM_OBJECT       object_type,
               int               x,
               int               y,
               int               size_x,
               int               size_y,
               color             color_bg,
               color             color_line,
               ENUM_BASE_CORNER  corner,
               ENUM_LINE_STYLE   line_style,
               int               line_width,
               bool              object_back,
               bool              selection,
               bool              hidden,
               long              z_order
               )
{
//---

      int sub_window = WindowFind("sample");
      
      ResetLastError();
      
   if(!ObjectCreate(ChartID(),object_name,OBJ_RECTANGLE_LABEL,sub_window,0,0))
   {
      Print(__FUNCTION__,
            ": failed to create a rectangle label! name: ",object_name," Error code = ",GetLastError());
      return(false);
   }

      ObjectSetInteger(ChartID(),object_name,OBJPROP_XDISTANCE,x);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_YDISTANCE,y);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_XSIZE,size_x);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_YSIZE,size_y);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_BGCOLOR,color_bg);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_CORNER,corner);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_COLOR,color_line);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_STYLE,line_style);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_WIDTH,line_width);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_BACK,object_back);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_SELECTABLE,selection);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_SELECTED,selection);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_HIDDEN,hidden);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_ZORDER,z_order);

      
      WindowRedraw();


   return(true);

}

//+------------------------------------------------------------------+
//| Create Label                                                     |
//+------------------------------------------------------------------+
bool createLabel( string            object_name,
                  int               x,
                  int               y,
                  ENUM_BASE_CORNER  corner,
                  string            text,
                  string            font,
                  int               font_size,
                  double            angle,
                  ENUM_ANCHOR_POINT anchor,
                  color             object_color,
                  bool              object_back,
                  bool              selection,
                  bool              hidden,
                  long              z_order
                )

{
//---

      int sub_window = WindowFind("sample");
      
      ResetLastError();
      
      if(!ObjectCreate(ChartID(),object_name,OBJ_LABEL,sub_window,0,0))
     {
         Print(__FUNCTION__,
            ": failed to create text label! name: ",object_name," Error code = ",GetLastError());
         return(false);
     }
      ObjectSetInteger(ChartID(),object_name,OBJPROP_XDISTANCE,x);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_YDISTANCE,y);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_CORNER,corner);
      ObjectSetString(ChartID(),object_name,OBJPROP_TEXT,text);
      ObjectSetString(ChartID(),object_name,OBJPROP_FONT,font);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_FONTSIZE,font_size);
      ObjectSetDouble(ChartID(),object_name,OBJPROP_ANGLE,angle);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_ANCHOR,anchor);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_COLOR,object_color);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_BACK,object_back);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_SELECTABLE,selection);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_HIDDEN,hidden);
      ObjectSetInteger(ChartID(),object_name,OBJPROP_ZORDER,z_order);
      
      WindowRedraw();


      return(true);
      
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         
                  const long& lparam,   
                  const double& dparam, 
                  const string& sparam  
                  )
{
//---
      if(id==CHARTEVENT_OBJECT_CLICK)
      {
         Print("The mouse has been clicked on the object with name '"+sparam+"'");
      }
}
Bambang Sugianto
10520
Bambang Sugianto  
don't use object label.. try object button..
SYED NAUFAL GADDAFI
1399
SYED NAUFAL GADDAFI  

I thought he is using object button when he says he click the button, unfortunately not. No wonder the button is not working like it should. Because it is not a button.


If he uses object button from the start, none of his problem arises.

metbright
101
metbright  

Thanks.

I just want the picture symbol as button I don't like OBJECT_BUTTON.

I think the OnChartEvent() can make anything as button by adding click event, but why recieve only the rectangle label event.

metbright
101
metbright  

Now I can solve the problem by use label with text "g" font "Webdings" as a background.

Thank you all.

12
To add comments, please log in or register