//+------------------------------------------------------------------+
//|                                                  NeedsInputs.mq5 |
//|                                                       Ali Rajput |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Ali Rajput"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property description "Refuses to start with its default inputs, the caller has to set the period"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
//+------------------------------------------------------------------+
//| Inputs: the default period is invalid on purpose                 |
//+------------------------------------------------------------------+
input group   "Main"
input int     InpPeriod=0;                  // must be set by the caller, 0 fails OnInit()
//+------------------------------------------------------------------+
//| Indicator buffers                                                |
//+------------------------------------------------------------------+
double Buf[];                               // InpPeriod on every bar
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(InpPeriod<=0)
     {
      PrintFormat("NeedsInputs: period %d is not valid",InpPeriod);
      return(INIT_PARAMETERS_INCORRECT);
     }
   SetIndexBuffer(0,Buf,INDICATOR_DATA);
   PrintFormat("NeedsInputs received: period=%d",InpPeriod);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   for(int i=(prev_calculated>0 ? prev_calculated-1 : 0); i<rates_total; i++)
      Buf[i]=InpPeriod;
   return(rates_total);
  }
//+------------------------------------------------------------------+
