Please add shortcut to deselect all objects on the chart
Hello .
On Tools>Options>Charts there is a checkbox reading "Select Object After Creation" ,uncheck that if you dont want objects to be automatically selected after creation .
There is also a choice in menu Charts>Objects>Unselect All
Other than that ,you can place this indicator in your default template .
//+------------------------------------------------------------------+ //| deselect_objects.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window input int Dsx=200;//Button Size X input int Dsy=20;//Button Size Y input int Dpx=0;//Button Position X input int Dpy=20;//Button Position Y input int Dfs=8;//Button Font Size input bool AutoHide=true;//Auto Hide input color Dbc=clrDodgerBlue;//Button Back Color input color Dbrdc=clrMidnightBlue;//Button Border Color input color Dtxtc=clrWheat;//Button Text Color input ENUM_BORDER_TYPE Dbrt=BORDER_FLAT;//Button Border Type //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ string SystemTag="DeSelector",SystemBtn; int DCSX=0,DCEX=0,DCSY=0,DCEY=0; int fDCSX=0,fDCEX=0,fDCSY=0,fDCEY=0; bool hidden=false; int OnInit() { //--- indicator buffers mapping ObjectsDeleteAll(ChartID(),SystemTag); SystemBtn=SystemTag+"_DeSelect_All"; if(AutoHide) { hidden=true; HS_Create_Btn(ChartID(),0,SystemBtn,Dsy,Dsy,Dpx,Dpy,"Arial",Dfs,Dbc,Dbrdc,Dbrt,Dtxtc,ALIGN_CENTER,"[>]",false,false); DCSX=Dpx; DCEX=DCSX+Dsy; DCSY=Dpy; DCEY=Dpy+Dsy; fDCSX=Dpx; fDCEX=fDCSX+Dsx; fDCSY=Dpy; fDCEY=Dpy+Dsy; ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); } if(!AutoHide){HS_Create_Btn(ChartID(),0,SystemBtn,Dsx,Dsy,Dpx,Dpy,"Arial",Dfs,Dbc,Dbrdc,Dbrt,Dtxtc,ALIGN_CENTER,"DeSelectAll [>]",false,false);} //--- return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { ObjectsDeleteAll(ChartID(),SystemTag); } //+------------------------------------------------------------------+ //| 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[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(AutoHide) { if(id==CHARTEVENT_MOUSE_MOVE) { int mcx=(int)lparam; int mcy=(int)dparam; //hidden bool state=hidden; if(state) { if(mcx>=DCSX&&mcx<=DCEX&&mcy>=DCSY&&mcy<=DCEY) { ShowBtn(); } } //not hidden if(!state) { bool hover=false; if(mcx>=fDCSX&&mcx<=fDCEX&&mcy>=fDCSY&&mcy<=fDCEY){hover=true;} if(!hover) { HideBtn(); } } } } if(id==CHARTEVENT_OBJECT_CLICK&&sparam==SystemBtn){DeSelectAll();if(AutoHide){HideBtn();}} } //+------------------------------------------------------------------+ void DeSelectAll() { int objs=ObjectsTotal(ChartID(),0); for(int o=0;o<objs;o++) { ObjectSetInteger(ChartID(),ObjectName(ChartID(),o,0),OBJPROP_SELECTED,false); } ChartRedraw(ChartID()); } void ShowBtn() { hidden=false; ObjectSetInteger(ChartID(),SystemBtn,OBJPROP_XSIZE,Dsx); ObjectSetString(ChartID(),SystemBtn,OBJPROP_TEXT,"DeSelectAll [>]"); ChartRedraw(ChartID()); } void HideBtn() { hidden=true; ObjectSetInteger(ChartID(),SystemBtn,OBJPROP_XSIZE,Dsy); ObjectSetString(ChartID(),SystemBtn,OBJPROP_TEXT,"[>]"); ChartRedraw(ChartID()); } //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); } } //CREATE BTN OBJECT ENDS HERE
Hello .
On Tools>Options>Charts there is a checkbox reading "Select Object After Creation" ,uncheck that if you dont want objects to be automatically selected after creation .
There is also a choice in menu Charts>Objects>Unselect All
Other than that ,you can place this indicator in your default template .
Thank You, this indicator works perfectly!!
Thank You, this indicator works perfectly!!
You are welcome
Hello .
On Tools>Options>Charts there is a checkbox reading "Select Object After Creation" ,uncheck that if you dont want objects to be automatically selected after creation .
There is also a choice in menu Charts>Objects>Unselect All
Other than that ,you can place this indicator in your default template .
Thanks. Great utility
Hello,
Could you please add shortcut to deselect all objects on chart in MT5? This could be really helpfull.
Best regards,
Pawel