Miscellaneous
0
Views
0
Downloads
0
Favorites
BREW_MissingData_sep
//+---------------------------------+
//| BREW_MissingData_Sep.mq4 |
//+---------------------------------+
#property copyright "Copyright © 2010, Brewmanz"
#property link "http://www.metaquotes.net/"
//#property indicator_chart_window
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 3
//---- input parameters
extern int AlertIfMissingPeriodsOver=10;
extern int AlertLimit=10;
//---- display buffers
double V1Buff[];
int AlertsToGo;
//+-------------------------------------------+
//| Custom indicator initialization function |
//+-------------------------------------------+
int init()
{
AlertsToGo = AlertLimit;
//Print("Init() starting");
string short_name;
IndicatorBuffers(1);
//---- indicator line
//SetIndexStyle( 0,DRAW_LINE);
SetIndexStyle( 0,DRAW_HISTOGRAM);
SetIndexBuffer(0,V1Buff);
//---- name for DataWindow and indicator subwindow label
short_name="BREW MissingData(" + AlertIfMissingPeriodsOver + ")";
IndicatorShortName(short_name);
SetIndexLabel(0,"100+MissingIntervals");
//----
SetIndexDrawBegin(0,1);
//----
//Print("Init() ending");
return(0);
}
//+--------------------------------------+
int start()
{
//Print("Start() top");
//----
//if(Bars<=AtrPeriod) return(0);
int ix, ixMax, ixP, counted_bars=IndicatorCounted();
//Print("Bars=",Bars,",IndCnt=",IndicatorCounted());
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- the last counted bar will be recounted
if(counted_bars>0) counted_bars--;
//---- count from oldest non-counted(treating most recent counted as to-be-recounted) to 0 (most recent)
ixMax=Bars-counted_bars;
for(ix = ixMax; ix >=0; ix--)
{
//if(ix > ixMax - TrailingBarsLength)//check if enough history to work
// continue;
datetime dThis = Time[ix];
datetime dPrev = Time[ix+1];
int periodStep = (dThis - dPrev)/(Period()*60);
// wait! if over weekend, deduct 'markets closed' time (49 hours)
if(TimeDayOfWeek(dThis) < TimeDayOfWeek(dPrev))
periodStep -= (49 * 60) / Period();
int periodMissed = periodStep - 1;
// is all okay?
if(periodMissed <= 0)
{
V1Buff[ix] = 0;//EMPTY_VALUE;
continue;
}
// oops. data is missing. could be weekend ...
if(TimeDayOfWeek(dThis) < TimeDayOfWeek(dPrev))
{
if(periodMissed * Period() == 49 * 60)
{
V1Buff[ix] = 0;//EMPTY_VALUE;
continue;
}
}
Print(TimeToStr(dPrev), "-", TimeToStr(dThis), " Missing ", periodMissed, " Periods of ", Period(), " mins");
if(periodMissed > AlertIfMissingPeriodsOver)
{
if(AlertsToGo > 0)
{
AlertsToGo--;
Alert(TimeToStr(dPrev), "-", TimeToStr(dThis), " Missing ", periodMissed, " Periods of ", Period(), " mins");
}
}
V1Buff[ix] = 100 + periodMissed;
}
//---- plot any calced values
//----
//Print("Start() ret");
return(0);
}
//+------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---