//+------------------------------------------------------------------+ //| AML.mq4 | //| andreybs | //| andreybs@yandex.ru | //+------------------------------------------------------------------+ #property copyright "Adaptive Market Level" #property link "andreybs@yandex.ru" /*-------------------------------------------------------------------- Адаптивный уровень рынка - показывает текущий опроный уровень рыночной цены. Уровень смещается только при трендовом движении цены. --------------------------------------------------------------------*/ #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Blue #property indicator_width1 2 //---- input parameters extern int Fractal=6; extern int Lag=7; //---- indicator buffers double aml[]; double lvl[]; double fr[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0,aml); SetIndexStyle(0,DRAW_LINE); SetIndexLabel(0,"AML"); SetIndexBuffer(1,lvl); SetIndexStyle(1,DRAW_NONE); SetIndexBuffer(2,fr); SetIndexStyle(2,DRAW_NONE); return(0); } //+------------------------------------------------------------------+ int start() { 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+Lag; for(int i=limit-1; i>=0; i--) { double R1 = Range(Fractal,i)/Fractal; double R2 = Range(Fractal,i+Fractal)/Fractal; double R3 = Range(2*Fractal,i)/(2*Fractal); double dim=0; if(R1+R2>0 && R3>0) dim=(MathLog(R1+R2)-MathLog(R3)) *1.44269504088896; double alpha=MathExp(-Lag*(dim-1.0)); if(alpha>1.0) alpha=1.0; if(alpha<0.01) alpha=0.01; double price=(High[i]+Low[i]+2*Open[i]+2*Close[i])/6; fr[i]=alpha*price+(1.0-alpha)*fr[i+1]; if(MathAbs(fr[i]-fr[i+Lag])>=Lag*Lag*Point) lvl[i]=fr[i]; else lvl[i]=lvl[i+1]; aml[i]=lvl[i]; } return(0); } //+------------------------------------------------------------------+ double Range(int count,int start) { double max = iHigh(Symbol(),Period(), iHighest(Symbol(),Period(),MODE_HIGH,count,start) ); double min = iLow(Symbol(),Period(), iLowest(Symbol(),Period(),MODE_LOW,count,start) ); return(max-min); } //+------------------------------------------------------------------+