//+------------------------------------------------------------------+ //| Quartiles.mq5 | //| Copyright © 2010, LeMan. | //| b-market@mail.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, LeMan." #property link "b-market@mail.ru" //---- indicator version #property version "1.00" //---- drawing the indicator in the main window #property indicator_chart_window //---- number of indicator buffers #property indicator_buffers 3 //---- 3 plots are used #property indicator_plots 3 //+-----------------------------------+ //| Indicator 1 drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a line #property indicator_type1 DRAW_LINE //---- teal color is used for the indicator line #property indicator_color1 Teal //---- the indicator line is a continuous curve #property indicator_style1 STYLE_SOLID //---- indicator line width is equal to 1 #property indicator_width1 1 //---- displaying the indicator label #property indicator_label1 "Upper Quartile" //+-----------------------------------+ //| Indicator 2 drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a line #property indicator_type2 DRAW_LINE //---- blue color is used for the indicator line #property indicator_color2 Blue //---- the indicator line is a continuous curve #property indicator_style2 STYLE_SOLID //---- indicator line width is equal to 1 #property indicator_width2 1 //---- displaying the indicator label #property indicator_label2 "Middle Quartile" //+-----------------------------------+ //| Indicator 3 drawing parameters | //+-----------------------------------+ //---- drawing the indicator as a line #property indicator_type3 DRAW_LINE //---- use orange color for the indicator line #property indicator_color3 Orange //---- the indicator line is a continuous curve #property indicator_style3 STYLE_SOLID //---- indicator line width is equal to 1 #property indicator_width3 1 //---- displaying the indicator label #property indicator_label3 "Lower Quartile" //+-----------------------------------+ //| Declaration of enumerations | //+-----------------------------------+ enum ENUM_APPLIED_PRICE_ // Type of constant { PRICE_CLOSE_ = 1, // Close PRICE_OPEN_, // Open PRICE_HIGH_, // High PRICE_LOW_, // Low PRICE_MEDIAN_, // Median Price (HL/2) PRICE_TYPICAL_, // Typical Price (HLC/3) PRICE_WEIGHTED_, // Weighted Close (HLCC/4) PRICE_SIMPLE, // Simple Price (OC/2) PRICE_QUARTER_, // Quarted Price (HLOC/4) PRICE_TRENDFOLLOW0_, // TrendFollow_1 Price PRICE_TRENDFOLLOW1_ // TrendFollow_2 Price }; //+-----------------------------------+ //| Indicator input parameters | //+-----------------------------------+ input int N=20; input double p1 = 0.25; input double p3 = 0.75; input ENUM_APPLIED_PRICE_ IPC=PRICE_CLOSE; // Applied price input int Shift=0; // Horizontal shift of the indicator in bars //+-----------------------------------+ //---- declaration of dynamic arrays that //---- will be used as indicator buffers double q1Buffer[]; double q2Buffer[]; double q3Buffer[]; //---- declaration of global variables int n1,n2t,n2f,n3; double PriceArray[]; //---- declaration of the integer variables for the start of data calculation int min_rates_total,N_; //+------------------------------------------------------------------+ //| Custom indicator indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //---- initialization of constants double P1=p1; if(p1>1){P1=1;Print("p1 parameter cannot be above 1! Default value equal to 1 will be used!");} if(p1<0){P1=0;Print("p1 parameter cannot be less than 0! Default value equal to 0 will be used!");} double P3=p3; if(p3>1){P3=1;Print("p3 parameter cannot be above 1! Default value equal to 1 will be used!");} if(p3<0){P3=0;Print("p3 parameter cannot be less than 0! Default value equal to 0 will be used!");} N_=N; if(N_<3){N_=3;Print("N parameter cannot be less than 3! Default value equal to 3 will be used!");} min_rates_total=N_; n1=int(MathRound(N_*P1)); if(!n1) n1=1; n2t = (N_+1)/2; n2f = N_/2; n3=int(MathRound(N_*P3)); if(!n3) n3=1; //---- memory distribution for variables' arrays if(ArrayResize(PriceArray,N_)0) q2=PriceArray[n2t-1]; else q2=(PriceArray[n2f-1]+PriceArray[n2f])/2; q1 = PriceArray[n1-1]; q3 = PriceArray[n3-1]; q1Buffer[bar] = NormalizeDouble(q1, _Digits); q2Buffer[bar] = NormalizeDouble(q2, _Digits); q3Buffer[bar] = NormalizeDouble(q3, _Digits); } //---- return(rates_total); } //+------------------------------------------------------------------+ //| Getting values of a price series | //+------------------------------------------------------------------+ double PriceSeries(uint applied_price, // Applied price uint bar, // Index of shift relative to the current bar for a specified number of periods back or forward). const double &Open[], const double &Low[], const double &High[], const double &Close[]) { //---- switch(applied_price) { //---- Price constants from the ENUM_APPLIED_PRICE enumeration case PRICE_CLOSE: return(Close[bar]); case PRICE_OPEN: return(Open [bar]); case PRICE_HIGH: return(High [bar]); case PRICE_LOW: return(Low[bar]); case PRICE_MEDIAN: return((High[bar]+Low[bar])/2.0); case PRICE_TYPICAL: return((Close[bar]+High[bar]+Low[bar])/3.0); case PRICE_WEIGHTED: return((2*Close[bar]+High[bar]+Low[bar])/4.0); //---- case 8: return((Open[bar] + Close[bar])/2.0); case 9: return((Open[bar] + Close[bar] + High[bar] + Low[bar])/4.0); //---- case 10: { if(Close[bar]>Open[bar])return(High[bar]); else { if(Close[bar]Open[bar])return((High[bar]+Close[bar])/2.0); else { if(Close[bar]