NRTR_ATR_STOP

NRTR_ATR_STOP
Indicators Used
Indicator of the average true range
0 Views
0 Downloads
0 Favorites
NRTR_ATR_STOP
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers  2
#property indicator_color1 Blue
#property indicator_color2 Red

extern int ATR=50;
extern int Coeficient=3;

double Up[],Dn[];
//+------------------------------------------------------------------+
int init()
{
  SetIndexBuffer(0,Up);
  SetIndexStyle (0,DRAW_LINE);
  SetIndexEmptyValue(0,0.0);
  SetIndexLabel (0,"Up");

  SetIndexBuffer(1,Dn);
  SetIndexStyle (1,DRAW_LINE);
  SetIndexEmptyValue(1,0.0);
  SetIndexLabel (1,"Dn");

  return(0);
}
int deinit() { return(0); }
//+------------------------------------------------------------------+
int start()
{
  int i,limit;
  double REZ;
  string MODE="UP";

  limit=Bars-ATR;
  for(i=limit; i>=0; i--)
  {
    Dn[i]=0; Up[i]=0;
    REZ=Coeficient*iATR(NULL,0,ATR,i);
    if(MODE=="DOWN" &&  Low[i]>Dn[i+1]) { Up[i+1]= Low[i+1]-REZ; MODE="UP";   }
    if(MODE=="UP"   && High[i]<Up[i+1]) { Dn[i+1]=High[i+1]+REZ; MODE="DOWN"; }

    if(MODE=="UP")
    {
      if(Low[i+1]>Up[i+1]+REZ) Up[i]=Low[i+1]-REZ;
		  else Up[i]=Up[i+1];
		}

    if(MODE=="DOWN")
    {
     	if(High[i+1]<Dn[i+1]-REZ) Dn[i]=High[i+1]+REZ;
	    else Dn[i]=Dn[i+1];
	  }
  }
  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 ---