High Low Previous Bar

Author: Copyright © 2021, Vladimir Karputov
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
High Low Previous Bar
ÿþ//+------------------------------------------------------------------+

//|                                        High Low Previous Bar.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

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

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

#property copyright "Copyright © 2021, Vladimir Karputov"

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

#property version   "1.000"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot High

#property indicator_label1  "Prev High"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrTomato

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Low

#property indicator_label2  "Prev Low"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrSlateBlue

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- input parameters

input group             "Arrow"

sinput uchar               Inp_Arrow_High_Code  = 174;         // High: symbol code from the Wingdings font

sinput int                 Inp_Arrow_High_Shift = 5;           // High: vertical shift of arrows in pixels

sinput uchar               Inp_Arrow_Low_Code   = 174;         // Low: symbol code from the Wingdings font

sinput int                 Inp_Arrow_Low_Shift  = 5;           // Low: vertical shift of arrows in pixels

//--- indicator buffers

double   HighBuffer[];

double   LowBuffer[];

//---

bool     m_init_error   = false;    // error on InInit

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- forced initialization of variables

   m_init_error   = false; // error on InInit

//---

   if(Period()>PERIOD_D1)

     {

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

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

                      "The chart timeframe cannot be> = D1!";

      if(MQLInfoInteger(MQL_TESTER)) // when testing, we will only output to the log about incorrect input parameters

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

      else // if the Expert Advisor is run on the chart, tell the user about the error

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

      //---

      m_init_error=true;

      return(INIT_SUCCEEDED);

     }

//--- indicator buffers mapping

   SetIndexBuffer(0,HighBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,LowBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_ARROW,Inp_Arrow_High_Code);

   PlotIndexSetInteger(1,PLOT_ARROW,Inp_Arrow_Low_Code);

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

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-Inp_Arrow_High_Shift);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,Inp_Arrow_Low_Shift);

//--- set as an empty value 0.0

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

//---

   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_init_error)

      return(0);

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      HighBuffer[0]=0.0;

      LowBuffer[0]=0.0;

      limit=1;

     }

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

     {

      HighBuffer[i]=high[i-1];

      LowBuffer[i]=low[i-1];

     }

//--- 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 ---