Author: Copyright © 2020, Vladimir Karputov
Price Data Components
Series array that contains open prices of each bar
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Open Level
ÿþ//+------------------------------------------------------------------+

//|                                                   Open Level.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 1

#property indicator_plots   1

//--- plot Open

#property indicator_label1  "Open"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrFuchsia

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- input parameters

input ENUM_TIMEFRAMES   Inp_period  = PERIOD_H1;   // Timeframe

//--- indicator buffer

double   OpenBuffer[];

//---

bool     m_global_error             = false;

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

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   if(Inp_period<Period())

     {

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

                      "E>4=>9 ?0@0<5B@ \"Timeframe\" =5 <>65B 1KBL ,( B5:CI53> B09<D@59<0!":

                      "Input parameter \"Timeframe\" cannot be LESS than the current timeframe!";

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

      m_global_error=true;

      return(INIT_SUCCEEDED);

     }

   double price_open=iOpen(Symbol(),Inp_period,0);

//--- indicator buffers mapping

   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_ARROW,159);

//--- Set the display of the symbol

   PlotIndexSetString(0,PLOT_LABEL,Symbol()+","+StringSubstr(EnumToString(Inp_period),7)+" Open");

//---

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

//--- main loop

   int limit=prev_calculated-1;

   if(prev_calculated==0)

      limit=0;

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

     {

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

      if(time[i]==m_prev_bars)

         continue;

      m_prev_bars=time[i];

      if(Inp_period==Period())

        {

         OpenBuffer[i]=open[i];

        }

      else

        {

         int bars_shift=iBarShift(Symbol(),Inp_period,time[i],false);

         if(bars_shift<0)

           {

            return(0);

            m_prev_bars=0;

           }

         double price_open=iOpen(Symbol(),Inp_period,bars_shift);

         if(price_open==0.0)

           {

            return(0);

            m_prev_bars=0;

           }

         OpenBuffer[i]=price_open;

        }

     }

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