Current Bar

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

//|                                                  Current Bar.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 1

#property indicator_plots   1

//--- plot Bar

#property indicator_label1  "Bar"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrDarkOrchid

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- input parameters

input uchar    InpCode  = 174;   // Code from the Wingdings charset

//--- indicator buffers

double   BarBuffer[];

//---

bool     m_glabal_error             = false;

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

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

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

      m_glabal_error=true;

      return(INIT_SUCCEEDED);

     }

//--- indicator buffers mapping

   SetIndexBuffer(0,BarBuffer,INDICATOR_DATA);

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

   PlotIndexSetInteger(0,PLOT_ARROW,InpCode);

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

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-5);

//--- set as an empty value 0

   PlotIndexSetDouble(0,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_glabal_error)

      return(0);

   if(rates_total<10)

      return(0);

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

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

     {

      if(prev_calculated==rates_total)

         return(rates_total);

     }

   m_prev_bars=time[rates_total-1];

//---

   MqlDateTime SCurrTime,SBarTime;

   TimeToStruct(time[rates_total-1],SCurrTime);

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

     {

      TimeToStruct(time[i],SBarTime);

      if(CompareTime(SCurrTime,SBarTime))

         BarBuffer[i]=high[i];

      else

         BarBuffer[i]=0.0;

     }

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

   return(rates_total);

  }

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

//| Compare time                                                     |

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

bool CompareTime(MqlDateTime &first_struct,MqlDateTime &second_struct)

  {

   if(Period()<PERIOD_H1)

      return((first_struct.hour==second_struct.hour) && first_struct.min==second_struct.min);

   else

      return(first_struct.hour==second_struct.hour);

  }

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

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