Shadow of yesterday

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

//|                                          Shadow of yesterday.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.003"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot YesterdayHigh

#property indicator_label1  "YesterdayHigh"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrDodgerBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot YesterdayLow

#property indicator_label2  "YesterdayLow"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrOrangeRed

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- indicator buffers

double   YesterdayHighBuffer[];

double   YesterdayLowBuffer[];

//---

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,YesterdayHighBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,YesterdayLowBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_ARROW,159);

   PlotIndexSetInteger(1,PLOT_ARROW,159);

//---

   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-1;

   if(prev_calculated==0)

     {

      limit=0;

      ArrayInitialize(YesterdayHighBuffer,0.0);

      ArrayInitialize(YesterdayLowBuffer,0.0);

     }

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

     {

      MqlRates rates_D1[];

      ArraySetAsSeries(rates_D1,true);

      int start_pos=0,count=2;

      int copy_rates_D1=CopyRates(Symbol(),PERIOD_D1,time[i],count,rates_D1);

      if(copy_rates_D1<1)

         return(0);

      if(copy_rates_D1==1)

        {

         YesterdayHighBuffer[i]=0.0;

         YesterdayLowBuffer[i]=0.0;

        }

      else

        {

         YesterdayHighBuffer[i]=rates_D1[1].high;

         YesterdayLowBuffer[i]=rates_D1[1].low;

        }

     }

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

   return(rates_total);

  }

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---