High Low First Bar

Author: Copyright © 2019, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
High Low First Bar
ÿþ//+------------------------------------------------------------------+

//|                                           High Low First Bar.mq5 |

//|                              Copyright © 2019, Vladimir Karputov |

//|                                           http://wmua.ru/slesar/ |

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

#property copyright "Copyright © 2019, Vladimir Karputov"

#property link      "http://wmua.ru/slesar/"

#property version   "1.000"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   2

//--- plot High

#property indicator_label1  "High"

#property indicator_type1   DRAW_ARROW

#property indicator_color1  clrTomato

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot Low

#property indicator_label2  "Low"

#property indicator_type2   DRAW_ARROW

#property indicator_color2  clrSlateBlue

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- input parameters 

input ushort   InpHighCode=119;  // Symbol code to draw "High"

input ushort   InpLowCode=119;   // Symbol code to draw "Low"

//--- indicator buffers

double         HighBuffer[];

double         LowBuffer[];

//---

int            day_of_year;

datetime       first_bar;

double         first_high;

double         first_low;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

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

   PlotIndexSetInteger(1,PLOT_ARROW,InpLowCode);

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

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-5);

   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,5);

//---

   day_of_year=-1;

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

   first_high=0.0;

   first_low=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[])

  {

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

      limit=0;

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

     {

      MqlDateTime STime;

      TimeToStruct(time[i],STime);

      if(STime.day_of_year!=day_of_year)

        {

         day_of_year=STime.day_of_year;

         first_bar=time[i];

         first_high=high[i];

         first_low=low[i];

        }

      else if(first_bar==time[i])

        {

         first_high=high[i];

         first_low=low[i];

        }

      HighBuffer[i]=first_high;

      LowBuffer[i]=first_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 ---