//+------------------------------------------------------------------+ //| Ouartiles.mq4 | //| Copyright © 2010, LeMan. | //| b-market@mail.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, LeMan." #property link "b-market@mail.ru" #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Red #property indicator_color2 Blue #property indicator_color3 Green //---- extern int N=20; extern int SetPrice=0; extern double p1 = 0.25; extern double p3 = 0.75; //---- double q1Buffer[]; double q2Buffer[]; double q3Buffer[]; //+------------------------------------------------------------------+ int init() { //---- IndicatorBuffers(3); IndicatorDigits(Digits); //---- indicators SetIndexBuffer(0,q1Buffer); SetIndexBuffer(1,q2Buffer); SetIndexBuffer(2,q3Buffer); //--- SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE); SetIndexStyle(2,DRAW_LINE); //---- if(N<=0) N=3; //---- SetIndexDrawBegin(0,N); SetIndexDrawBegin(1,N); SetIndexDrawBegin(2,N); //---- IndicatorShortName("Ouartiles"); SetIndexLabel(0,"q1"); SetIndexLabel(1,"q2"); SetIndexLabel(2,"q3"); //---- return(0); } //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ int start() { int i,j; int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; int limit = Bars - counted_bars; if(counted_bars==0) limit-=1+N; //---- double PriceArray[]; ArrayResize(PriceArray,N); //---- for(i = 0; i< limit; i++) { for(j = 0; j < N; j++) { PriceArray[j]=GetPrice(i+j); } ArraySort(PriceArray); if(N%2>0) { int n2=(N+1)/2; double q2=PriceArray[n2-1]; } else { n2 = N/2; q2 = (PriceArray[n2-1]+PriceArray[n2])/2; } int n1=MathRound(N*p1); double q1=PriceArray[n1-1]; int n3=MathRound(N*p3); double q3=PriceArray[n3-1]; q1Buffer[i] = NormalizeDouble(q1, Digits); q2Buffer[i] = NormalizeDouble(q2, Digits); q3Buffer[i] = NormalizeDouble(q3, Digits); } //---- return(0); } //+------------------------------------------------------------------+ double GetPrice(int Shift) { double price; //---- switch(SetPrice) { case 0: price = Close[Shift]; break; case 1: price = Open[Shift]; break; case 2: price = High[Shift]; break; case 3: price = Low[Shift]; break; case 4: price = (High[Shift]+Low[Shift])/2.0; break; case 5: price = (High[Shift]+Low[Shift]+Close[Shift])/3.0; break; case 6: price = (High[Shift]+Low[Shift]+2*Close[Shift])/4.0; break; case 7: price = (Open[Shift]+High[Shift]+Low[Shift]+Close[Shift])/4.0; break; case 8: price = (Open[Shift]+Close[Shift])/2.0; break; default: price = 0.0; } //---- return(price); } //+------------------------------------------------------------------+