Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Color Day - MetaTrader 5 Script | Forex Indicator Download - MT4/MT5 Resources - MetaTrader 5 Resources

author EAcpu | 3 reads | 0 comments |

Color Day - indicator for MetaTrader 5

The Color Day indicator colors bullish and bearish days.

If the daily closing price is greater than the opening price, the color is blue (customizable in settings).

 input color up = blue; // color for bullish days

If the daily closing price is less than the opening price, the color is red (customizable in settings).

 Input color DN = red; // color for bearish days

Copy the opening price, closing price, and opening time days for a specified number of days:

 Copy time ( void , PERIOD_D1 , 0 , days + 1 , tm);
copyopen ( void , PERIOD_D1 , 0 , day + 1 , operation);
ReplicationClose ( void , PERIOD_D1 , 0 , days + 1 , cl);

to the corresponding array:

 Date and time tm[]; double operation[]; double cl[];

Before installing the indicator to the chart, set the dimensions of the array:

 Integer initialization ()
  { //--- indicator buffer mapping comment ( "" );
arrayresize (tm, days);
arrayResize (ops, days);
Array resize (cl, days); //--- return ( initialization successful );
  }

Assign the value of the array cell to a variable and determine the off time for each day Time 1 :

 datetimetime0 =tm[i];
datetimetime1 =time0+ 3600 * 24 ;
Doubledopen =op[i];
Double dclose=cl[i];

Use the placerect() function:

 Blank placement rectangle ( string name, date time t1, double p1, date time t2, double p2, color clear)
  {
Object delete ( 0 , name); //--- Create a rectangle by given coordinates Object create ( 0 , name, OBJ_rectangle , 0 ,t1,p1,t2,p2); //--- Set the rectangle color object set integer ( 0 , name, OBJPROP_COLOR , clr); //--- Enable (true) or disable (false) filled rectangle mode object set integer ( 0 , name, OBJPROP_FILL , true );
  }

Color the day based on price action:

 if (dclose  "Rectangle" + ( thin string )dopen, time0,dopen, time1,dclose,DN);
if (dclose>dopen) PutRect( "rectangle" + ( thin string )dopen, time 0, doopen, time 1, dclose, UP);

Iterate over all the days specified by the parameters in the loop :

for ( integer i= 0 ;i<=day;i++)
    {
Copy time ( void , PERIOD_D1 , 0 , days + 1 , tm);
copyopen ( void , PERIOD_D1 , 0 , day + 1 , operation);
ReplicationClose ( void , PERIOD_D1 , 0 , days + 1 , cl);

datetimetime0 =tm[i];
datetimetime1 =time0+ 3600 * 24 ;
Doubledopen =op[i];
Double dclose=cl[i];

if (dclose  "Rectangle" + ( thin string )dopen, time0,dopen, time1,dclose,DN);
if (dclose>dopen) PutRect( "rectangle" + ( thin string )dopen, time 0, doopen, time 1, dclose, UP);

Remove object() function when removing an indicator from a chart using:

 BlankDeleteObject ()
  {
for ( integer i = total number of objects ( 0 , 0 , obj_rectangle ) - 1 ; i >= 0 ; i - )
     {
string_name = object_name ( 0 , i , 0 , obj_rectangle );
if ( String find (name, "rectangle" , 0 )>= 0 ) object delete ( 0 , name);
    }
  }


Remove the created object from the chart:

 Blank solution initialization ( constant integer reason)
  {
Comment ( "" );
  deleteObject();
  }
 Enter the integer number of days = 11 ; // Calculate the number of days
input color up = blue; // color for bullish days
Input color DN = red; // color for bearish days

Color Day - indicator for MetaTrader 5

Figure 1. Indicators on the chart


Attachment download

📎 colorday.mq5 (7.48 KB)

Source: MQL5 #16383

Verification code Refresh