Previous Day Arrow

Author: Copyright © 2020, Vladimir Karputov
1 Views
1 Downloads
0 Favorites
Previous Day Arrow
ÿþ//+------------------------------------------------------------------+

//|                                           Previous Day 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.001"

//---

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_plots   3

//--- plot High

#property indicator_label1  "High"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Price

#property indicator_label2  "Price"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrSpringGreen

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot Low

#property indicator_label3  "Low"

#property indicator_type3   DRAW_ARROW

#property indicator_color3  clrRed

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

//--- input parameters

input ENUM_APPLIED_PRICE   Inp_applied_price    = PRICE_MEDIAN;   // Type of price

input ushort               InpHighBufferCode    = 159;            // High: code from the Wingdings charset

input ushort               InpPriceBufferCode   = 159;            // Price: code from the Wingdings charset

input ushort               InpLowBufferCode     = 159;            // Low: code from the Wingdings charset

//--- indicator buffers

double   HighBuffer[];

double   PriceBuffer[];

double   LowBuffer[];

//---

datetime m_prev_bars                = 0;        // "0" -> D'1970.01.01 00:00';

bool     m_global_error             = false;    // global error

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,HighBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,PriceBuffer,INDICATOR_DATA);

   SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);

//--- setting a code from the Wingdings charset as the property of PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,InpHighBufferCode);

   PlotIndexSetInteger(1,PLOT_ARROW,InpPriceBufferCode);

   PlotIndexSetInteger(2,PLOT_ARROW,InpLowBufferCode);

//--- Set as an empty value 0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);

   if(Period()>=PERIOD_D1)

     {

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

                  ""09<D@59< =5 <>65B 1KBL >= D1!":

                  "The timeframe cannot be >= D1!";

      Alert(__FUNCTION__,", ERROR! ",text);

      m_global_error=true;

     }

//---

   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(m_global_error)

      return(0);

//--- we work only at the time of the birth of new bar

   if(time[rates_total-1]==m_prev_bars)

      return(rates_total);

   m_prev_bars=time[rates_total-1];

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      limit=0;

      m_prev_bars=0;

     }

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

     {

      int bar_d1=iBarShift(Symbol(),PERIOD_D1,time[i],false);

      if(bar_d1<0)

        {

         m_prev_bars=0;

         return(0);

        }

      double   o_prev_d1   = iOpen(Symbol(),PERIOD_D1,bar_d1+1);

      double   h_prev_d1   = iHigh(Symbol(),PERIOD_D1,bar_d1+1);

      double   l_prev_d1   = iLow(Symbol(),PERIOD_D1,bar_d1+1);

      double   c_prev_d1   = iClose(Symbol(),PERIOD_D1,bar_d1+1);

      HighBuffer[i]        = h_prev_d1;

      LowBuffer[i]         = l_prev_d1;

      switch(Inp_applied_price)

        {

         case PRICE_CLOSE:

            PriceBuffer[i]=c_prev_d1;

            break;

         case PRICE_OPEN:

            PriceBuffer[i]=o_prev_d1;

            break;

         case PRICE_HIGH:

            PriceBuffer[i]=h_prev_d1;

            break;

         case PRICE_LOW:

            PriceBuffer[i]=l_prev_d1;

            break;

         case PRICE_MEDIAN:

            PriceBuffer[i]=(h_prev_d1 + l_prev_d1)/2.0;

            break;

         case PRICE_TYPICAL:

            PriceBuffer[i]=(h_prev_d1 + l_prev_d1 + c_prev_d1)/3.0;

            break;

         case PRICE_WEIGHTED:

            PriceBuffer[i]=(h_prev_d1 + l_prev_d1 + c_prev_d1 + c_prev_d1)/4.0;

            break;

        }

     }

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

   return(rates_total);

  }

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

Comments