iVAR





//+------------------------------------------------------------------+
//|                                                         iVAR.mq4 |
//|                                        (C)opyright © 2008, Ilnur |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

//   Èíäèêàòîð îòîáðàæàåò èíäåêñ âàðèàöèè öåíîâîãî ðÿäà, âû÷èñëåííîãî
// íà ìèíèìàëüíîì ïðåäøåñòâóþùåì èíòåðâàëå äëèíû 2^n. Èíäåêñ âàðèàöèè
// ïîêàçûâàåò, ÷òî ïðåîáëàäàåò âî âðåìåííîì ðÿäó  òðåíäîâàÿ èëè ôëåòîâàÿ
// ñîñòàâëÿþùàÿ, èëè æå ðÿä âåäåò ñåáÿ ñëó÷àéíî.

// Ì.Ì. Äóáîâèêîâ è äð. - Ðàçìåðíîñòü ìèíèìàëüíîãî ïîêðûòèÿ è ëîêàëüíûé
// àíàëèç ôðàêòàëüíûõ âðåìåííûõ ðÿäîâ.

#property copyright "(C)opyright © 2008, Ilnur"
#property link      "http://www.metaquotes.net"
//---- íàñòðîéêè èíäèêàòîðà
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_level1 0.5
//---- âõîäíûå ïàðàìåòðû
extern int n = 5;
//---- áóôåð èíäèêàòîðà
double ibuffer[];
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíèöèàëèçàöèè èíäèêàòîðà                                 |
//+------------------------------------------------------------------+
int init()
{
//---- íàñòðîéêà ïàðàìåòðîâ îòðèñîâêè
   SetIndexBuffer(0,ibuffer);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexDrawBegin(0,MathPow(2,n));
   SetIndexLabel(0,"iVAR");
//---- "êîðîòêîå èìÿ" îòîáðàæàåìîå â îêíå èíäèêàòîðà
   IndicatorShortName("iVAR("+n+")");
   return(0);
}
//+------------------------------------------------------------------+
//| Îñíîâíàÿ ôóíêöèÿ èíäèêàòîðà                                      |
//+------------------------------------------------------------------+
int start()
{
   int i, j, k, nTotal, nCountedBars = IndicatorCounted();
   int ihigh, ilow, nInterval, nWindow = MathPow(2,n);
   double Delta, Xñ, Yñ, Sx, Sy, Sxx, Sxy;
//---- ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
   nTotal = Bars-nWindow;
   if(nCountedBars>nWindow) nTotal = Bars-nCountedBars-1;
//---- îñíîâíîé öèêë èíäèêàòîðà
   for(j=nTotal; j>=0; j--)
   {
      Sx = 0; Sy = 0; Sxx = 0; Sxy = 0;
      for(i=0; i<=n; i++)
      {
         nInterval = MathPow(2,n-i);
      //---- ñóììèðóåì ðàçíèöû ìàêñèìàëüíîé è ìèíèìàëüíîé öåí íà èíòåðâàëå
         for(Delta=0, k=0; k<MathPow(2,i); k++)
         {
         	ihigh = iHighest(Symbol(),0,MODE_HIGH,nInterval,nInterval*k+j);
         	ilow = iLowest(Symbol(),0,MODE_LOW,nInterval,nInterval*k+j);
         	Delta += High[ihigh]-Low[ilow];
         }
      //---- âû÷èñëÿåì êîîðäèíàòû âàðèàöèè â äâîéíîì ëîãàðèôìè÷åñêîì ìàñøòàáå
         Xñ = (n-i)*MathLog(2.0);
         Yñ = MathLog(Delta);
      //---- íàêàïëèâàåì äàííûå äëÿ íàõîæäåíèÿ êîýôôèöèåíòîâ ëèíèè ðåãðåññèè ñ ïîìîùüþ ÌÍÊ
         Sx += Xñ; 
         Sy += Yñ;
         Sxx += Xñ*Xñ; 
         Sxy += Xñ*Yñ;
      }
   //---- âû÷èñëÿåì èíäåêñ âàðèàöèè (êîýôôèöèåíò íàêëîíà ëèíèè ðåãðåññèè)
      ibuffer[j] = -(Sx*Sy-(n+1)*Sxy)/(Sx*Sx-(n+1)*Sxx);
   }
   return(0);
}



Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:


Implements a curve of type DRAW_LINE

Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: