Your are very close with your code, except that the date constant is expressed as: D'2016.02.01' (for the first of February, 2016).
I would do something like this:
Code: Select all
static const datetime expiryDate = D'2016.01.06';
int OnInit() {
if ( TimeCurrent() > expiryDate ) {
return(INIT_FAILED);
}
//---
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 ( TimeCurrent() > expiryDate ) {
MessageBox("Indicator has expired.","Expiry Error",0);
ExpertRemove();
return(0);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
Your use of Time[0] would work too, except that if the indicator was installed on a MN1 chart, it would still work until the end of the month. I use TimeCurrent() (i.e. server time) so that users can not get the indicator to work, by changing the computer clock. Also, I like to have a check inside the OnCalculate() (or OnStart()), so that it would be removed real-time once the clock ticks over beyond the expiry date.
Hope this helps.