//+------------------------------------------------------------------+ //| WPR.mq5 | //| Copyright 2009, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "2009, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property description "Larry Williams' Percent Range" //---- indicator settings #property indicator_separate_window #property indicator_level1 -20.0 #property indicator_level2 -80.0 #property indicator_levelstyle STYLE_DOT #property indicator_levelcolor Silver #property indicator_levelwidth 1 #property indicator_maximum 0.0 #property indicator_minimum -100.0 #property indicator_buffers 1 #property indicator_plots 1 #property indicator_type1 DRAW_LINE #property indicator_color1 DodgerBlue //---- input parameters input int InpWPRPeriod=14; // Period //---- buffers double ExtWPRBuffer[]; //--- global variables int ExtPeriodWPR; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- check for input value if(InpWPRPeriod<3) { ExtPeriodWPR=14; Print("Incorrect InpWPRPeriod value. Indicator will use value=",ExtPeriodWPR); } else ExtPeriodWPR=InpWPRPeriod; //---- name for DataWindow and indicator subwindow label IndicatorSetString(INDICATOR_SHORTNAME,"%R"+"("+string(ExtPeriodWPR)+")"); //---- indicator's buffer SetIndexBuffer(0,ExtWPRBuffer); PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodWPR-1); //--- digits IndicatorSetInteger(INDICATOR_DIGITS,2); //---- } //+------------------------------------------------------------------+ //| Williams’ Percent Range | //+------------------------------------------------------------------+ 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 &TickVolume[], const long &Volume[], const int &Spread[]) { //---- insufficient data if(rates_totalcur_position-period;i--) { if(Highestcur_position-period;i--) { if(Lowest>array[i]) Lowest=array[i]; } return(Lowest); } //+------------------------------------------------------------------+