ChangeObjectsColor

Download script
Author: sHell
ChangeObjectsColor

This script is a utility tool designed for MetaTrader users to quickly and efficiently manage the visual appearance of their trading charts. Its primary purpose is to automate the process of changing colors for various drawing objects—such as lines, shapes, and text—without having to modify each one individually.

Core Functionality

The logic operates based on three different levels of filtering, allowing you to choose how broad or specific you want the color change to be:

1. Global Update (Broadest) If no specific categories or names are selected, the script will scan every single object currently on your chart and update their colors simultaneously. This is useful for a complete visual overhaul of the workspace.

2. Targeted Filtering (Intermediate) The script allows you to select specific types of drawing tools. You can choose to update only certain classes of objects, such as:

  • Trend lines and Gann fans
  • Fibonacci levels and rectangles
  • Arrows, labels, and text elements
  • Geometric shapes like ellipses or triangles

3. Named Filtering (Most Specific) For the highest level of precision, the script can look for specific names. If you provide a partial name or a unique identifier, the script will only change the colors of objects that contain that specific text in their name.

Intelligent Color Logic

To ensure the tool is as flexible as possible, it includes two intelligent "rules" for how it handles colors:

  • Color Replacement: By default, the script replaces existing colors with a new "Target Color" defined by the user.
  • Selective Filtering: You can enable a specific mode that tells the script to only change objects if they currently match a specific "Old Color." If this is turned off, the script will ignore the current color and update everything regardless.

How it Works in Practice

When you run the script, it performs a comprehensive scan of your chart's visual elements. It cross-references every object against your chosen criteria (Type, Name, or Global status). If an object meets your requirements, the script automatically applies the new color instantly. This eliminates the tedious manual labor of clicking through dozens of different lines and indicators to adjust your chart's aesthetic.

11 Views
0 Downloads
0 Favorites
ChangeObjectsColor
//+------------------------------------------------------------------+
//|                                           ChangeObjectsColor.mq4 |
//|                                          Andrew Shelkovenko, SPb |
//|                                                   diakin@list.ru |
//+------------------------------------------------------------------+
#property copyright "sHell"
#property link      "diakin@list.ru"
#property show_inputs


// Based on 
//+------------------------------------------------------------------+
//|                                                  CLEAR_CHART.mq4 |
//|                                            Aleksandr Pak, Almaty |
//|                                                   ekr-ap@mail.ru |
//+------------------------------------------------------------------+


/*
if UseOldColor=true change colors for objects that color=OldColor

If all fields set false - change colors for all objects

If one field set true = change color of this object type only
If the change_by_Partial_name field not empty = change color of this object that name contains this field substring

If field Trend_line=true is set; // change color of Trend lines only
........................
åñëè âñå ïîëÿ óñòàíîâëåíû â false - ìåíÿåò öâåò âñåõ îáúåêòîâ
åñëè õîòÿ áû îäíî ïîëå óñòàíîâëåíî â true = ìåíÿåò öâåò òîëüêî îáúåêòîâ ýòîãî òèïà
íàïðèìåð:
åñëè çàäàíî ïîëå change_by_Partial_name = ìåíÿåò öâåò âñåõ îáúåêòîâ èìÿ êîòîðûõ ñîäåðæèò çàäàííóþ ïîäñòðîêó
åñëè çàäàíî ïîëå Trend_line=true; //ìåíÿåò öâåò âñåõ òðåíäîâûõ ëèíèé
*/
extern string change_by_Partial_name="";

extern bool UseOldColor=false;
extern color OldColor=Blue;
extern color NewColor=Aqua;


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 objname; 
   int j,k,_type;
   color objcolor;
   k=ObjectsTotal();
   bool w1=false;
   //Comment ("Begin..............");
   
   for(j=0;j<24;j++) if(u[j]) w1=true;
      
      if(!w1 && StringLen(change_by_Partial_name)==0)
         
         for (int i=k-1;i>=0; i--) //ìåíÿåì âñå \change all
         {
         objname=ObjectName(i);
         
         objcolor=ObjectGet( objname, OBJPROP_COLOR) ;
         if ((objcolor==OldColor && UseOldColor==true) || UseOldColor==false)
         ObjectSet( objname, OBJPROP_COLOR, NewColor);
         }
      else
    {
         if(StringLen(change_by_Partial_name)!=0) 
            for (i=k-1;i>=0; i--)
            {
            objname=ObjectName(i);
   //         Comment ("objname",objname);
            
            objcolor=ObjectGet( objname, OBJPROP_COLOR) ;
            int found=StringFind(objname,change_by_Partial_name,0);
            if ( found>=0 && ( (objcolor==OldColor && UseOldColor==true) || UseOldColor==false) ) 
            {
            
   //         Comment ("Found=",objname);
            ObjectSet( objname, OBJPROP_COLOR, NewColor);
            }
            }
   
      if(w1)//åñëè õîòü îäèí
         for (i=k-1;i>=0; i--)//èçìåíåíèå ïî òèïó//change by type
         {
         objname=ObjectName(i);
         _type=ObjectType(objname);
         objcolor=ObjectGet( objname, OBJPROP_COLOR) ;
         if(_type>=0 && _type<=23)
            {
            for(j=0;j<24;j++)
            if (u[_type] && ( (objcolor==OldColor && UseOldColor==true) || UseOldColor==false) ) 
            ObjectSet( objname, OBJPROP_COLOR, NewColor) ;
            }
         }
      }//else
   
   return(0);
  }

Comments