Days of the week color v2

Author: Copyright © 2020, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Days of the week color v2
ÿþ//+------------------------------------------------------------------+

//|                                    Days of the week color v2.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2020, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property version   "2.000"

#property indicator_separate_window

#property description "Days of the week in the form of a color histogram"

#property description "New in version 2: any day of the week can be turned off"

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   1

//--- plot Histogram

#property indicator_label1  "Day colors"

#property indicator_type1   DRAW_COLOR_HISTOGRAM

//--- define 7 colors for coloring sections

#property indicator_color1  clrCyan,clrRed,clrYellowGreen,clrBlue,clrYellow,clrNavy,clrGold

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- input parameters

input bool     InpSunday      = true;  // Sunday

input bool     InpMonday      = true;  // Monday

input bool     InpTuesday     = true;  // Tuesday

input bool     InpWednesday   = true;  // Wednesday

input bool     InpThursday    = true;  // Thursday

input bool     InpFriday      = true;  // Friday

input bool     InpSaturday    = true;  // Saturday

//--- indicator buffers

double         HistogramBuffer[];

double         HistogramColors[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,HistogramBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,HistogramColors,INDICATOR_COLOR_INDEX);

//--- indicator digits

   IndicatorSetInteger(INDICATOR_DIGITS,0);

//--- indicator short name

   IndicatorSetString(INDICATOR_SHORTNAME,"Day");

//--- Sunday

   if(!InpSunday)

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrNONE);

   else

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrCyan);

//--- Monday

   if(!InpMonday)

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrNONE);

   else

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,clrRed);

//--- Tuesday

   if(!InpTuesday)

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrNONE);

   else

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,clrYellowGreen);

//--- Wednesday

   if(!InpWednesday)

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,3,clrNONE);

   else

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,3,clrBlue);

//--- Thursday

   if(!InpThursday)

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,4,clrNONE);

   else

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,4,clrYellow);

//--- Friday

   if(!InpFriday)

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,5,clrNONE);

   else

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,5,clrNavy);

//--- Saturday

   if(!InpSaturday)

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,6,clrNONE);

   else

      PlotIndexSetInteger(0,PLOT_LINE_COLOR,6,clrGold);

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| 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[])

  {

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

      limit=0;

   for(int i=limit; i<rates_total; i++)

     {

      MqlDateTime STime;

      TimeToStruct(time[i],STime);

      switch(STime.day_of_week)

        {

         case  0:

            HistogramBuffer[i]=0;

            HistogramColors[i]=0;

            break;

         case  1:

            HistogramBuffer[i]=1;

            HistogramColors[i]=1;

            break;

         case  2:

            HistogramBuffer[i]=2;

            HistogramColors[i]=2;

            break;

         case  3:

            HistogramBuffer[i]=3;

            HistogramColors[i]=3;

            break;

         case  4:

            HistogramBuffer[i]=4;

            HistogramColors[i]=4;

            break;

         case  5:

            HistogramBuffer[i]=5;

            HistogramColors[i]=5;

            break;

         case  6:

            HistogramBuffer[i]=6;

            HistogramColors[i]=6;

            break;

        }

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments