//+------------------------------------------------------------------+ //| iWPR_HTF.mq5 | //| Copyright © 2012, Nikolay Kositsin | //| Khabarovsk, farria@mail.redcom.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2012, Nikolay Kositsin" #property link "farria@mail.redcom.ru" //---- indicator version number #property version "1.00" #property description "Larry Williams' Percent Range" //---- drawing indicator in a separate window #property indicator_separate_window //---- number of indicator buffers 1 #property indicator_buffers 1 //---- only one plot is used #property indicator_plots 1 //+----------------------------------------------+ //| Parameters of displaying horizontal levels | //+----------------------------------------------+ #property indicator_level1 -80.0 #property indicator_level2 -20.0 #property indicator_levelcolor Gray #property indicator_levelstyle STYLE_DASHDOTDOT //+----------------------------------------------+ //| Window borders showing parameters | //+----------------------------------------------+ #property indicator_maximum 0.0 #property indicator_minimum -100.0 //+----------------------------------------------+ //| Declaration of constants | //+----------------------------------------------+ #define RESET 0 // the constant for getting the command for the indicator recalculation back to the terminal #define INDICATOR_NAME "iWPR" // the constant for the indicator name //+----------------------------------------------+ //| Indicator drawing parameters | //+----------------------------------------------+ //---- drawing the indicator 1 as a symbol #property indicator_type1 DRAW_SECTION //---- the following colors are used for the indicator #property indicator_color1 clrBlueViolet //---- indicator 1 line width is equal to 2 #property indicator_width1 2 //---- displaying the indicator label #property indicator_label1 INDICATOR_NAME //+-------------------------------------+ //| Indicator input parameters | //+-------------------------------------+ input ENUM_TIMEFRAMES TimeFrame=PERIOD_H4; // Chart period input uint WPR_Period=14; // Period of averaging input int Shift=0; // Horizontal shift of the indicator in bars //+-------------------------------------+ //---- declaration of dynamic arrays that further will be used as indicator buffers double IndBuffer[]; //---- declaration of a variable for storing the indicator initialization result bool Init; //---- declaration of strings string Symbol_,Word; //---- declaration of integer variables for the indicators handles int Ind_Handle; //---- declaration of the integer variables for the start of data calculation int min_rates_total; //+------------------------------------------------------------------+ //| Getting string timeframe | //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) { //---- return(StringSubstr(EnumToString(timeframe),7,-1)); //---- } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { Init=true; //---- checking correctness of the chart periods if(TimeFramerates_total || prev_calculated<=0)// checking for the first start of calculation of an indicator { limit=rates_total-min_rates_total-2; // starting index for calculation of all bars LastCountBar=limit; } else limit=int(LastCountBar)+rates_total-prev_calculated; // starting index for calculation of new bars //---- indexing elements in arrays as timeseries ArraySetAsSeries(time,true); //---- main cycle of calculation of the indicator for(bar=limit; bar>=0 && !IsStopped(); bar--) { //---- zero out the contents of the indicator buffers for calculation IndBuffer[bar+1]=EMPTY_VALUE; //---- copy newly appeared data in the iTime array if(CopyTime(Symbol_,TimeFrame,time[bar],1,iTime)<=0) return(RESET); if(time[bar]>=iTime[0] && time[bar+1]