Author: Alexandr Sokolov
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
ATR UD
ÿþ#property copyright "Alexandr Sokolov"

#property link      "https://www.facebook.com/sokolov6897"

#property description "ATR Up and Down"

#property strict

#property indicator_separate_window

#property indicator_buffers 4

//--- 04048< 2>7<>6=K5 20@80=BK 2K1>@0 4;O  lines ----------------

enum LINES

  {

   yes, //Yes

   no   //No

  };

//--- E>4=K5 ?0@0<5B@K () ----------------------------------------

input int   period = 14;  //Period

input LINES lines  = yes; //Calculate values without period

//--- 1JO2;O5< 1CD5@K ----------------------------------------------

double UP[],        // 07=8F0 <564C High 8 Open 70 ... period

       DOWN[],      // 07=8F0 <564C Open 8 Low 70 ... period

       line_UP[],   // 07=8F0 <564C High 8 Open 157 CGQB0 ?5@8>40

       line_DOWN[]; // 07=8F0 <564C Open 8 Low 157 CGQB0 ?5@8>40

//--- 1JO2;O5< AB0B8G5A:85 ?5@5<5==K5 ------------------------------

static double for_UP, for_DOWN; //A?><030B5;L=K5 ?5@5<5==K5 4;O @0AGQB>2 1CD5@>2 UP 8 DOWN

//-------------------------------------------------------------------------------------------------

int OnInit()

  {

  //--- 04048< :>;8G5AB2> 7=0:>2 ?>A;5 45AOB8G=>9 B>G:8 ------------

   IndicatorDigits(Digits());

  //--- UP ----------------------------------------------------------

   SetIndexBuffer(0,UP);                                   //8=8O !0 1C45B >B>1@060BL 7=0G5=8O 87 1CD5@0 UP

   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2,clrGreen); //04048< B8?, AB8;L, H8@8=C 8 F25B 4;O ;8=88 !0

   SetIndexLabel(0,"UP");                                  //@>?8H5< >?8A0=85 4;O ;8=88 !0, :>B>@>5 1C45B ?>O2;OBAO ?@8 =02545=88 :C@A>@0 <KH:8 =0 =5Q

  //--- DOWN --------------------------------------------------------

   SetIndexBuffer(1,DOWN);                               //;O ;8=88 !1 2AQ 7040QBAO 0=0;>38G=K< >1@07>< :0: 4;O ;8=88 !0

   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2,clrRed);

   SetIndexLabel(1,"DOWN");

  //--- #:065< ?5@4=07=0G5=85 1CD5@>2 line_UP 8 line_DOWN -----------

   ENUM_INDEXBUFFER_TYPE display;               //'5@57 ?5@5<5==CN display ?5@54048< B8? 1CD5@>2 4;O ;8=89 !2 8 !3

   if(lines == yes) {display = INDICATOR_DATA;} //5A;8(lines @02=> yes) B> {7=0G5=8O line_UP 8 line_DOWN 1C4CB >B@8A>2K20BLAO 2 >:=5 8=48:0B>@0}

   else {display = INDICATOR_CALCULATIONS;};    //8=0G5 {7=0G5=8O line_UP 8 line_DOWN =5 1C4CB >B@8A>2K20BLAO 2 >:=5 8=48:0B>@0};

  //--- line_UP -----------------------------------------------------

   SetIndexBuffer(2,line_UP,display);                //@82O7K205< 1CD5@ : ;8=88 !2 8 C:07K205< =C6=> ;8 >B@8A>2K20BL MB>B 1CD5@

   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,clrBlue); //0;55 2AQ 0=0;>38G=> :0: 2 ?5@2KE 42CE ?@8<5@0E

   SetIndexLabel(2,"UP without period");

  //--- line_DOWN ---------------------------------------------------

   SetIndexBuffer(3,line_DOWN,display);              //;O ;8=88 !3 2AQ 7040QBAO 0=0;>38G=K< >1@07>< :0: 4;O ;8=88 !2

   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1,clrBlue);

   SetIndexLabel(3,"DOWN without period");

  //-----------------------------------------------------------------

   return(INIT_SUCCEEDED);

  }

//-------------------------------------------------------------------------------------------------

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

   int limit = rates_total - prev_calculated - period; if(limit < 1) {limit = 1;}; // 1) 040Q< ;8<8B 4;O F8:;0

   for(int i = 0; i < limit; i++) // 2) 040Q< CA;>28O F8:;0 (8=8F80;870F8O F8:;0, 5A;8 i <5=LH5 limit {2K?>;=O5< :@C3}, ?>A;5 2K?>;=5=8O :@C30)

     {

      if(lines == yes)                    // 3) A;8  lines @025= yes

        {

         line_UP[i] = High[i] - Open[i];  // 3) KG8A;O5< 7=0G5=8O 1CD5@0 line_UP

         line_DOWN[i] = Low[i] - Open[i]; // 3) 8 line_DOWN

        };

      for_UP = 0; for_DOWN = 0; Values(i); // 4) 1=C;O5< AB0B8G5A:85 ?5@5<5==K5 8 AC<8@C5< @07=8FK <564C F5=0<8 4;O 1CD5@>2 UP 8 DOWN

      UP[i] = for_UP / period; DOWN[i] = for_DOWN / period; // 8)  0AG8BK205< 8 ?@8A208205< 7=0G5=8O 1CD5@0< UP 8 DOWN

     };

  //-----------------------------------------------------------------

   return(rates_total);

  }

//--- $C=:F8O 4;O AC<8@>20=8O @07=8F <564C F5=0<8 70 n ?5@8>4 >B ?>;CG5==>3> i --------------------

void Values(int i)

  {

   int limit = i + period;        // 5) 040Q< ;8<8B 4;O F8:;0 A CGQB>< ?5@8>40

   for(int a = i; a < limit; a++) // 6) 040Q< CA;>28O F8:;0

     {

      for_UP = for_UP + (High[a] - Open[a]);    // 7) @>AB> AC<8@C5< @07=8FC 4;O UP

      for_DOWN = for_DOWN + (Low[a] - Open[a]); // 7) @>AB> AC<8@C5< @07=8FC 4;O DOWN

     };

  }

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