This script is a specialized utility designed for the MetaTrader 4 platform to help traders quickly clean up and organize their trading charts. Its primary purpose is to automate the removal of various visual elements—such as drawing tools, indicators, and labels—so that users can refresh their workspace without having to delete every item manually one by one.
The logic operates based on three different "cleaning modes" depending on how you configure the settings:
1. Full Chart Reset
If no specific options are selected and no custom names are provided, the script acts as a complete "wipe." When activated, it will identify every single object currently visible on your chart and remove them all instantly, leaving you with a completely blank trading screen.
2. Selective Removal by Name
You can use the script to target specific items based on their names. By entering a specific word or phrase into the "Partial Name" field, the script will scan your chart and delete only the objects that contain that specific text within their title. This is useful for removing groups of tools that share a common naming convention while leaving everything else untouched.
3. Specific Tool Filtering
The script includes a comprehensive list of checkboxes covering almost every type of drawing tool available in MetaTrader, including:
- Geometry & Lines: Vertical lines, horizontal lines, trend lines (including those by angle), and rectangles.
- Advanced Technical Drawings: Gann fans/grids, Fibonacci levels (arcs, fans, channels), regression channels, pitchforks, and ellipses.
- Annotations: Text labels, arrows, and custom cycles.
When you check one or more of these specific boxes, the script becomes highly precise: it will only delete the types of objects you have selected. For example, if you only check "Trend Line," the script will remove all trend lines but leave your Fibonacci levels and text notes exactly where they are.
Summary of Operation
The tool is designed to be intelligent about its workflow. It scans the chart from the background forward, ensuring it captures every object correctly. It prioritizes your specific instructions—whether you want a total reset, a targeted name-based cleanup, or a refined removal of specific drawing categories—giving you full control over your workspace environment with a single click.
//+------------------------------------------------------------------+
//| CLEAR_CHART.mq4 |
//| Aleksandr Pak, Almaty |
//| ekr-ap@mail.ru |
//+------------------------------------------------------------------+
#property copyright "AP"
#property link "ekr-ap@mail.ru"
#property show_inputs
/*
If all fields inactive - are deleted by all
If one field = is set even deletes only this type
For example:
If the field delete_Partial_name = ààà // óäàëzåò all having it as a part of a name is set
If field Trend_line=true is set; // deletes all inclined lines
........................
åñëè âñå ïîëÿ íåàêòèâíûå - óäàëÿåò âñå
åñëè çàäàíî õîòÿ áû îäíî ïîëå = óäàëÿåò òîëüêî ýòîò òèï
íàïðèìåð:
åñëè çàäàíî ïîëå delete_Partial_name = ààà //óäàëzåò âñå èìåþùåå ýòî êàê ÷àñòü èìåíè
åñëè çàäàíî ïîëå Trend_line=true; //óäàëÿåò âñå íàêëîííûå ëèíèè
*/
extern string delete_on_Partial_name="";
extern bool Vertical_line=false;
extern bool Horisontal_line=false;
extern bool Trend_line=false;
extern bool Trendbyangle_line=false;
extern bool Regression_chanel=false;
extern bool _chanel=false;
extern bool StdDev_chanel=false;
extern bool Gann_line=false;
extern bool GannFan=false;
extern bool GannGrid=false;
extern bool FIBO=false;
extern bool FIBO_times=false;
extern bool FIBO_fan=false;
extern bool FIBO_arc=false;
extern bool Expansion=false;
extern bool FIBO_channel=false;
extern bool Restangle=false;
extern bool Triangle=false;
extern bool Ellipse=false;
extern bool PitchFork=false;
extern bool Cycles=false;
extern bool Text=false;
extern bool Arrow=false;
extern bool Label=false;
bool u[24];
int init()
{
u[0]=Vertical_line; u[1]=Horisontal_line; u[2]=Trend_line; u[3]=Trendbyangle_line;
u[4]=Regression_chanel; u[5]=_chanel; u[6]=StdDev_chanel; u[7]=Gann_line;
u[8]=GannFan; u[9]=GannGrid; u[10]=FIBO; u[11]=FIBO_times;
u[12]=FIBO_fan; u[13]=FIBO_arc; u[14]=Expansion; u[15]=FIBO_channel;
u[16]=Restangle; u[17]=Triangle; u[18]=Ellipse; u[19]=PitchFork;
u[20]=Cycles; u[21]=Text; u[22]=Arrow; u[23]=Label;
}
int start()
{
//----
string s;
int j,k,_type;
k=ObjectsTotal();
bool w1=false;
for(j=0;j<24;j++) if(u[j]) w1=true;
if(!w1&&StringLen(delete_on_Partial_name)==0)
for (int i=k-1;i>=0; i--) //óäàëÿåì âñå//delte ALL
{
s=ObjectName(i);
ObjectDelete(s);
}else
{
if(StringLen(delete_on_Partial_name)!=0)
for (i=k-1;i>=0; i--)//óäàëÿåì ïàðòèþ//delete partial
{
s=ObjectName(i);
if(StringFind(s,delete_on_Partial_name,0)>=0)ObjectDelete(s);
}
if(w1)//åñëè õîòü îäèí
for (i=k-1;i>=0; i--)//óäàëåíèå ïî òèïó//delete by type
{
s=ObjectName(i);
_type=ObjectType(s);
if(_type>=0&&_type<=23)
{
for(j=0;j<24;j++)
if(u[_type]) ObjectDelete(s);
}
}
}//else
return(0);
}
Comments