Author: Copyright � 2011, Vladimir Hlystov
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
SL_ATR_v1x
//+------------------------------------------------------------------+
//|                                                       SL_ATR.mq4 |
//|                               Copyright © 2011, Vladimir Hlystov |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Vladimir Hlystov"
#property link      "cmillion@narod.ru"
 
#property indicator_chart_window
#property  indicator_buffers 4
#property  indicator_color1  Blue
#property  indicator_color2  Red
#property  indicator_color3  Red
#property  indicator_color4  Blue
 
//+------------------------------------------------------------------+
extern int   Period_ATR     =14;//ïåðèîä ÀÒR
//+------------------------------------------------------------------+
double SLSell[],SLBay[];
double     BufferBuy[];
double     BufferSell[];
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,234);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,233);
//---- indicator buffers mapping
   SetIndexBuffer(0,SLSell);
   SetIndexBuffer(1,SLBay);
   SetIndexBuffer(2,BufferBuy);
   SetIndexBuffer(3,BufferSell);
//---- name for DataWindow and indicator subwindow label
   SetIndexLabel(0,"SL Sell ");
   SetIndexLabel(1,"SL Bay ");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars = IndicatorCounted();      
   if(counted_bars > 0) counted_bars--;
   int limit = Bars-counted_bars;
   if(counted_bars==0) limit-=1+2;
   double ATR = iATR(Symbol(),0,Period_ATR,limit);
   SLBay[limit]=NormalizeDouble(High[limit] + ATR,Digits);
   SLSell[limit]=NormalizeDouble(Low[limit] - ATR,Digits);
   for(int i=limit-1; i>=0; i--) 
   {
      ATR = iATR(Symbol(),0,Period_ATR,i);
      if (NormalizeDouble(High[i] + ATR,Digits)<=SLBay[i+1] || SLBay[i+1]==EMPTY_VALUE) SLBay[i]  = NormalizeDouble(High[i] + ATR,Digits);
      //else SLBay[i]=SLBay[i+1];
      if (High[i]>=SLBay[i]) SLBay[i]=EMPTY_VALUE;
      if (SLBay[i+2]==EMPTY_VALUE && SLBay[i+1]>=SLBay[i] && SLBay[i]!=EMPTY_VALUE) BufferBuy[i+1]=SLBay[i+1];
      
      if (NormalizeDouble(Low[i]  - ATR,Digits)>=SLSell[i+1] || SLSell[i+1]==EMPTY_VALUE) SLSell[i] = NormalizeDouble(Low[i]  - ATR,Digits);
      //else SLSell[i]=SLSell[i+1];
      if (Low[i]<=SLSell[i]) SLSell[i]=EMPTY_VALUE;
      if (SLSell[i+2]==EMPTY_VALUE && SLSell[i+1]<=SLSell[i] && SLSell[i]!=EMPTY_VALUE) BufferSell[i+1]=SLSell[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 ---