Day Filling

Author: Copyright © 2021, Vladimir Karputov
Price Data Components
Miscellaneous
It issuies visual alerts to the screen
2 Views
0 Downloads
0 Favorites
Day Filling
ÿþ//+------------------------------------------------------------------+

//|                                                  Day Filling.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   1

//--- plot Day

#property indicator_label1  "Day"

#property indicator_type1   DRAW_FILLING

#property indicator_color1  clrLimeGreen,clrLavender

//--- indicator buffers

double   DayBuffer1[];

double   DayBuffer2[];

//---

bool     m_init_error               = false;    // error on InInit

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,DayBuffer1,INDICATOR_DATA);

   SetIndexBuffer(1,DayBuffer2,INDICATOR_DATA);

//--- INDICATOR_EMPTY_VALUE (empty value) will not participate in calculation of

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//--- set the display of the symbol

   PlotIndexSetString(0,PLOT_LABEL,"Day High;"+"Day Low;");

//---

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

//---

   if(Period()>=PERIOD_D1)

     {

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

                      "5@8>4 3@0D8:0 =5 <>65B 1KBL >= D1!":

                      "Chart period 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);

     }

//---

   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(rates_total<10)

      return(0);

   if(m_init_error)

      return(0);

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      DayBuffer1[0]=0.0;

      DayBuffer2[0]=0.0;

      limit=1;

     }

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

     {

      //--- get index of the bar corresponding to the specified time (time[i])

      int bar_shift_d1=iBarShift(Symbol(),PERIOD_D1,time[i],false);

      if(bar_shift_d1<0)

         return(0);

      //--- get index of the bar corresponding to the specified time (time[i-1])

      int bar_shift_d1_prev=iBarShift(Symbol(),PERIOD_D1,time[i-1],false);

      if(bar_shift_d1_prev<0)

         return(0);

      if(bar_shift_d1!=bar_shift_d1_prev)

        {

         int d=0;

        }

      //--- gets history data PERIOD_D1

      MqlRates rates_d1[];

      ArraySetAsSeries(rates_d1,true);

      if(CopyRates(Symbol(),PERIOD_D1,bar_shift_d1,1,rates_d1)<1)

         return(0);

      //---

      if(rates_d1[0].open<rates_d1[0].close)

        {

         DayBuffer1[i]=rates_d1[0].low;

         DayBuffer2[i]=rates_d1[0].high;

        }

      else

        {

         DayBuffer1[i]=rates_d1[0].high;

         DayBuffer2[i]=rates_d1[0].low;

        }

      //---

      if(bar_shift_d1_prev!=bar_shift_d1)

        {

         DayBuffer1[i-1]=0.0;

         DayBuffer2[i-1]=0.0;

        }

     }

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