Line in time

Author: Copyright © 2019, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Line in time
ÿþ//+------------------------------------------------------------------+

//|                                                 Line in time.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_separate_window

#property indicator_buffers 1

#property indicator_plots   1

//--- plot Line

#property indicator_label1  "Line"

#property indicator_type1   DRAW_HISTOGRAM

#property indicator_color1  clrMediumTurquoise

#property indicator_style1  STYLE_SOLID

#property indicator_width1  3

//--- input parameters

input uchar    InputHour   = 15; // Hour

input uchar    InputMinute = 01; // Minute

//--- indicator buffer

double         LineBuffer[];

//---

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

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA);

//--- set accuracy

   IndicatorSetInteger(INDICATOR_DIGITS,0);

//--- set maximum and minimum for subwindow  

   IndicatorSetDouble(INDICATOR_MINIMUM,0.0);

   IndicatorSetDouble(INDICATOR_MAXIMUM,1.0);

//--- sets drawing line empty value--

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

  {

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

      limit=0;

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

     {

      datetime time_d1[1];

      if(CopyTime(Symbol(),PERIOD_D1,time[i],1,time_d1)!=1)

         return(0);

      int d=0;

      MqlDateTime STime;

      TimeToStruct(time[i],STime);



      long current_bar_sec = STime.hour*60*60+STime.min*60+STime.sec;

      long input_sec       = InputHour*60*60+InputMinute*60;

      long next_bar_sec    = STime.hour*60*60+STime.min*60+STime.sec+PeriodSeconds(Period());



      if(current_bar_sec<=input_sec && input_sec<next_bar_sec)

         LineBuffer[i]=1.0;

      else

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