Days of the week color ARROW

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

//|                                 Days of the week color ARROW.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   "1.000"

#property indicator_chart_window

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



#property indicator_buffers 2

#property indicator_plots   1

//--- plot Histogram

#property indicator_label1  "Day colors"

#property indicator_type1   DRAW_COLOR_ARROW

//--- define 8 colors for coloring sections

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

#property indicator_style1  STYLE_SOLID

#property indicator_width1  2

//--- input parameters

input uchar    InpCode     = 108;   // Arrow code for style DRAW_ARROW (font Wingdings)

input int      InpShift    = 10;    // Vertical shift of arrows in pixels

//--- indicator buffers

double   ArrowBuffer[];

double   ArrowColors[];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,ArrowBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,ArrowColors,INDICATOR_COLOR_INDEX);

//--- define the symbol code for drawing in PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,InpCode);

//--- set the vertical shift of arrows in pixels

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-InpShift);

//--- set as an empty value 0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//--- indicator digits

   IndicatorSetInteger(INDICATOR_DIGITS,0);

//--- indicator short name

   IndicatorSetString(INDICATOR_SHORTNAME,"Day");

//---

   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:

            ArrowColors[i]=0;

            break;

         case  1:

            ArrowColors[i]=1;

            break;

         case  2:

            ArrowColors[i]=2;

            break;

         case  3:

            ArrowColors[i]=3;

            break;

         case  4:

            ArrowColors[i]=4;

            break;

         case  5:

            ArrowColors[i]=5;

            break;

         case  6:

            ArrowColors[i]=6;

            break;

        }

      ArrowBuffer[i]=high[i];

     }

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

   return(rates_total);

  }

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

Comments