Author: MetaQuotes
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
AtrSmColor
//AtrSmColor äëÿ ýòîãî èíäèêàòîðà íóæåí èíäèêàòîð SmAtr
//îí íàõîäèòñÿ âíèçó êîäà çàêîìåíòèðîâàí, åñëè âû ñêà÷àëè èíäèêàòîð AtrSmColor ñ ÌÊË êîäåáàçû
//ñêà÷àéòå òàì æå èíäèêàòîð SmAtr
#property copyright "Martingeil"
#property link      "fx.09@mail.ru"
//---- indicator settings
#property indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Yellow
#property  indicator_color2  Blue
#property  indicator_color3  Red

#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
//---- input parameters
extern double    t3_period=8.0;
extern int       AtrPeriod=14;
extern double    b=0.7;
//---- indicator buffers
double     ExtBuffer0[];
double     ExtBuffer1[];
double     ExtBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);//áóôåð ñèíåé ëèíèè
   SetIndexBuffer(2,ExtBuffer2);//áóôåð êðàñíîé ëèíèè   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("AtrSmColor");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| AtrSmColor                                                       |
//+------------------------------------------------------------------+
int start()
  {
   int    limit;
   int    counted_bars=IndicatorCounted();

   double atr;
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- atr
   if(counted_bars==0) limit-=1+1;
   for(int i=0; i<limit; i++)
     {
      atr=iCustom(Symbol(),0,"SmATR",t3_period,AtrPeriod,b,0,i);
      ExtBuffer0[i]=atr;
     }
//---- dispatch values between 2 buffers
   for(i=limit; i>=0; i--)
     {
      ExtBuffer1[i] = EMPTY_VALUE; if(ExtBuffer0[i]>ExtBuffer0[i+1]) ExtBuffer1[i] = ExtBuffer0[i];
      ExtBuffer2[i] = EMPTY_VALUE; if(ExtBuffer0[i]<ExtBuffer0[i+1]) ExtBuffer2[i] = ExtBuffer0[i];
     }
//---- done
   return(0);
  }
//--------------------------------------------------------------------------------------------------

/*
//+------------------------------------------------------------------+
//|                                                        SmATR.mq4 |
//|                                                       MetaQuotes |
//|                 http://forum.alpari-idc.ru/viewtopic.php?t=48186 |
//+------------------------------------------------------------------+
#property copyright "MetaQuotes"
#property link      "http://forum.alpari-idc.ru/viewtopic.php?t=48186"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Gold

//---- input parameters
extern double    t3_period=8.0;
extern int       AtrPeriod=14;
extern double    b=0.7;

//---- buffers
double ExtMapBuffer1[];

double e1Buffer[];
double e2Buffer[];
double e3Buffer[];
double e4Buffer[];
double e5Buffer[];
double e6Buffer[];

double c1,c2,c3,c4,n,w1,w2,b2,b3;
double dpo,t3,ATR;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
     string short_name;
//---- indicators
   IndicatorBuffers(8);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);

   SetIndexBuffer(2,e1Buffer);
   SetIndexBuffer(3,e2Buffer);
   SetIndexBuffer(4,e3Buffer);
   SetIndexBuffer(5,e4Buffer);
   SetIndexBuffer(6,e5Buffer);
   SetIndexBuffer(7,e6Buffer);
   
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0);
   SetIndexEmptyValue(4,0.0);
   SetIndexEmptyValue(5,0.0);
   SetIndexEmptyValue(6,0.0);
   SetIndexEmptyValue(7,0.0);
   
   //---- name for DataWindow and indicator subwindow label
   short_name="SmATR("+AtrPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   
   //----
   b2=b*b;
   b3=b2*b;
   c1=-b3;
   c2=(3*(b2+b3));
   c3=-3*(2*b2+b+b3);
   c4=(1+3*b+b3+3*b2);
   n=t3_period;

   if(n<1) n=1;
   n = 1 + 0.5*(n-1);
   w1 = 2 / (n + 1);
   w2 = 1 - w1;

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int shift,limit;
   if (counted_bars==0) limit=Bars-AtrPeriod;
   if (counted_bars>=0) limit=Bars-counted_bars;
   limit--;

   for (shift=limit;shift>=0;shift--)
      {//Begin
   
      ATR=iATR(NULL,0,AtrPeriod,shift);
      dpo=ATR;
      e1Buffer[shift] = w1*dpo + w2*e1Buffer[shift+1];
      e2Buffer[shift] = w1*e1Buffer[shift] + w2*e2Buffer[shift+1];
      e3Buffer[shift] = w1*e2Buffer[shift] + w2*e3Buffer[shift+1];
      e4Buffer[shift] = w1*e3Buffer[shift] + w2*e4Buffer[shift+1];
      e5Buffer[shift] = w1*e4Buffer[shift] + w2*e5Buffer[shift+1];
      e6Buffer[shift] = w1*e5Buffer[shift] + w2*e6Buffer[shift+1];

      t3 = c1*e6Buffer[shift] + c2*e5Buffer[shift] + c3*e4Buffer[shift] + c4*e3Buffer[shift];

      if (t3==0) t3=0.0001;

      ExtMapBuffer1[shift]=t3;  
   }
   return(0);
  }
//+------------------------------------------------------------------+
*/
//+------------------------------------------------------------------+

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 ---