//+------------------------------------------------------------------+ //| Custom Moving Averages.mq4 | //| Copyright 2011-2016,HPC Sphere Pvt. Ltd. India | //| https://www.hpcsphere.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2011-2016, HPC Sphere Pvt. Ltd. India" #property version "2.00" #property description "Custom Moving Averages" #property link "https://www.hpcsphere.com" #property icon "\\Images\\hpcs_logo.ico" #property strict #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red //--- indicator parameters extern int InpMAPeriod=14; // Period input int InpMAShift=0; // Shift input ENUM_MA_METHOD InpMAMethod=MODE_SMA; // Method input ENUM_APPLIED_PRICE Applied_Price = PRICE_CLOSE; // Applied Price //--- indicator buffer double ExtLineBuffer[]; void func_AlertInvalidPeriod() { if (Bars > 0) { if (InpMAPeriod >= Bars) { // Alert("Custom Moving Averages' Period(" + IntegerToString(InpMAPeriod) + ") is not less than the total number of bars (" + IntegerToString(Bars) + ") on the chart"); InpMAPeriod = 14; Alert("Using default \"Period\" value of " + IntegerToString(InpMAPeriod) + " to plot the Custom Moving Averages"); }} } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(void) { string short_name; func_AlertInvalidPeriod(); int draw_begin=InpMAPeriod-1; //--- indicator short name switch(InpMAMethod) { case MODE_SMA : short_name="SMA("; break; case MODE_EMA : short_name="EMA("; draw_begin=0; break; case MODE_SMMA : short_name="SMMA("; break; case MODE_LWMA : short_name="LWMA("; break; default : return(INIT_FAILED); } IndicatorShortName(short_name+string(InpMAPeriod)+")"); IndicatorDigits(Digits); //--- check for input if(InpMAPeriod<2) return(INIT_FAILED); //--- drawing settings SetIndexStyle(0,DRAW_LINE); SetIndexShift(0,InpMAShift); SetIndexDrawBegin(0,draw_begin); //--- indicator buffers mapping SetIndexBuffer(0,ExtLineBuffer); //--- initialization done return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Moving Average | //+------------------------------------------------------------------+ 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[]) { func_AlertInvalidPeriod(); //--- check for bars count if(rates_total