#ifndef TF_INDICATORS_CHART_OBJECTS_MQH
#define TF_INDICATORS_CHART_OBJECTS_MQH

bool TF_UpsertLabel(const long chart_id,const string name,const string text,
                    const int x,const int y,const color text_color,
                    const int font_size=9,const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER,
                    const int subwindow=0)
  {
   if(ObjectFind(chart_id,name)<0)
     {
      if(!ObjectCreate(chart_id,name,OBJ_LABEL,subwindow,0,0)) return(false);
      ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(chart_id,name,OBJPROP_HIDDEN,true);
      ObjectSetInteger(chart_id,name,OBJPROP_BACK,false);
      ObjectSetString(chart_id,name,OBJPROP_FONT,"Segoe UI");
     }
   ObjectSetInteger(chart_id,name,OBJPROP_CORNER,corner);
   ObjectSetInteger(chart_id,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_id,name,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,font_size);
   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,text_color);
   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
   return(true);
  }

bool TF_UpsertRectangleLabel(const long chart_id,const string name,
                             const int x,const int y,const int width,const int height,
                             const color background,const color border,
                             const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER,
                             const int subwindow=0)
  {
   if(ObjectFind(chart_id,name)<0)
     {
      if(!ObjectCreate(chart_id,name,OBJ_RECTANGLE_LABEL,subwindow,0,0)) return(false);
      ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(chart_id,name,OBJPROP_HIDDEN,true);
      ObjectSetInteger(chart_id,name,OBJPROP_BACK,false);
     }
   ObjectSetInteger(chart_id,name,OBJPROP_CORNER,corner);
   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_BGCOLOR,background);
   ObjectSetInteger(chart_id,name,OBJPROP_BORDER_COLOR,border);
   return(true);
  }

void TF_DeleteObjectsByPrefix(const long chart_id,const string prefix)
  {
   ObjectsDeleteAll(chart_id,prefix,-1,-1);
  }

string TF_Ellipsize(const string value,const int max_chars)
  {
   if(StringLen(value)<=max_chars) return(value);
   if(max_chars<=3) return(StringSubstr(value,0,max_chars));
   return(StringSubstr(value,0,max_chars-3)+"...");
  }

#endif
