Author: Adaptive Market Level
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
AML
//+------------------------------------------------------------------+ 
//|                                                          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);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---