Author: Copyright © 2020, Vladimir Karputov
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Day shape
ÿþ//+------------------------------------------------------------------+

//|                                                    Day shape.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.002"

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_plots   1

//--- plot Shape

#property indicator_label1  "Shape"

#property indicator_type1   DRAW_COLOR_LINE

#property indicator_color1  clrDodgerBlue,clrTomato

#property indicator_style1  STYLE_SOLID

#property indicator_width1  3

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

//| Enum Price                                                       |

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

enum ENUM_PRICE

  {

   price_regular=0,     // Regular (Curr 'O' and Curr 'C')

   price_close=1,       // Close (Prev 'C' and Curr 'C')

   price_open=2,        // Open (Prev 'O' and Curr 'O')

   price_high=3,        // Maximum (Prev 'H' and Curr 'H')

   price_low=4,         // Minimum (Prev 'L' and Curr 'L')

   price_median=5,      // Median (Prev ('H'+'L')/2  and Curr ('H'+'L')/2)

   price_typical=6,     // Typical (Prev ('H'+'L'+'C')/3 and Curr ('H'+'L'+'C')/3)

   price_average=7,     // Average (Prev (('H'+'L'+'C'+'C')/4 and Curr ('H'+'L'+'C'+'C')/4)

  };

//--- input parameters

input ENUM_PRICE        Inp_applied_price = price_regular;  // Type of price

//--- indicator buffers

double   ShapeBuffer[];

double   ShapeColors[];

//---

int         m_day=-1;

MqlDateTime m_STime;

//---

bool glabal_error=false;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   if(Period()>=PERIOD_D1)

     {

      string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")?

                      "5@8>4 3@0D8:0 =5 <>65B 1KBL @025= 8;8 1>;LH5 'D1'!":

                      "The chart period cannot be equal to or greater than 'D1'!";

      Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);

      glabal_error=true;

      return(INIT_SUCCEEDED);

     }

//--- indicator buffers mapping

   SetIndexBuffer(0,ShapeBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,ShapeColors,INDICATOR_COLOR_INDEX);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,0);

//--- name for DataWindow

   string short_name="-";

   switch(Inp_applied_price)

     {

      case price_regular:

         short_name="Regular prices";

         break;

      case price_close:

         short_name="Close price";

         break;

      case price_open:

         short_name="Open price";

         break;

      case price_high:

         short_name="Maximum price";

         break;

      case price_low:

         short_name="Minimum price";

         break;

      case price_median:

         short_name="Median price";

         break;

      case price_typical:

         short_name="Typical price";

         break;

      case price_average:

         short_name="Average price";

         break;

     }

   IndicatorSetString(INDICATOR_SHORTNAME,short_name);

//---

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

  {

   if(glabal_error)

      return(0);

   if(rates_total<10)

      return(0);

//---

   int limit=prev_calculated;

   if(prev_calculated==0)

     {

      ShapeBuffer[0]=0.0;

      ShapeColors[0]=0;

      limit=1;

     }

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

     {

      TimeToStruct(time[i],m_STime);

      if(m_day!=m_STime.day)

        {

         m_day=m_STime.day;

         ShapeBuffer[i]=0;

         ShapeColors[i]=0;

         continue;

        }



      double price_prev,price_curr;

      switch(Inp_applied_price)

        {

         case  price_regular:

            price_prev=open[i];

            price_curr=close[i];

            break;

         case price_close:

            //--- Close price

            price_prev=close[i-1];

            price_curr=close[i];

            break;

         case price_open:

            //--- Open price

            price_prev=open[i-1];

            price_curr=open[i];

            break;

         case price_high:

            //--- The maximum price for the period

            price_prev=high[i-1];

            price_curr=high[i];

            break;

         case price_low:

            //--- The minimum price for the period

            price_prev=low[i-1];

            price_curr=low[i];

            break;

         case price_median:

            //--- Median price, (high + low)/2

            price_prev=(high[i-1]+low[i-1])/2.0;

            price_curr=(high[i]+low[i])/2.0;

            break;

         case price_typical:

            //--- Typical price, (high + low + close)/3

            price_prev=(high[i-1]+low[i-1]+close[i-1])/3.0;

            price_curr=(high[i]+low[i]+close[i])/3.0;

            break;

         default:

            //--- Average price, (high + low + close + close)/4

            price_prev=(high[i-1]+low[i-1]+close[i-1]+close[i-1])/4.0;

            price_curr=(high[i]+low[i]+close[i]+close[i])/4.0;

            break;

        }



      if(price_prev<price_curr)

        {

         ShapeBuffer[i]=ShapeBuffer[i-1]+1;

         ShapeColors[i]=0;

         continue;

        }

      if(price_prev>price_curr)

        {

         ShapeBuffer[i]=ShapeBuffer[i-1]-1;

         ShapeColors[i]=1;

         continue;

        }

      ShapeBuffer[i]=ShapeBuffer[i-1];

      ShapeColors[i]=ShapeColors[i-1];

     }

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

   return(rates_total);

  }

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

Comments