True Range Bands

Author: Copyright � 2010, basisforex@gmail.com
True Range Bands
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each bar
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
True Range Bands
/*------------------------------------------------------------------+
 |                                             True Range Bands.mq4 |
 |                                                 Copyright © 2010 |
 |                                             basisforex@gmail.com |
 +------------------------------------------------------------------*/
#property copyright "Copyright © 2010, basisforex@gmail.com"
#property link      "basisforex@gmail.com"
//----
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 Yellow
#property indicator_color3 Yellow
//----
extern int       nPeriod     = 13;
extern double    Deviation   = 1.618;
extern int       MaShift     = 0;
//----
double MaBuffer[];
double MaTUp[];
double MaTDn[];
//+------------------------------------------------------------------+
int init()
 {
   SetIndexShift(0, MaShift);
   SetIndexShift(1, MaShift);
   SetIndexShift(2, MaShift);
//----
   SetIndexBuffer(0, MaBuffer);
   SetIndexBuffer(1, MaTUp);
   SetIndexBuffer(2, MaTDn);
//----
   SetIndexStyle(0, DRAW_LINE, STYLE_DOT);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE);
//----
   SetIndexLabel(0, "MA");
   SetIndexLabel(1, "MaUp");
   SetIndexLabel(1, "MaDn");
//----
   return(0);
 }
//+------------------------------------------------------------------+
int start()
 {
   int limit;
   double a;
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) return(-1);
   if(counted_bars > 0) counted_bars--;
   limit = Bars - counted_bars;
   for(int i = 0; i < limit; i++)
    {
      for(int j = 0; j < nPeriod; j++)
       {
         a = a + (iHigh(NULL, 0, i + j) + iLow(NULL, 0, i + j) + iClose(NULL, 0, i + j) * 2) / 4;
       }       
      MaBuffer[i]  =  a / nPeriod;
      a = 0;
      if(iClose(NULL, 0, i) > MaBuffer[i])
       {
         MaTUp[i] = MaBuffer[i] + iATR(NULL, 0, nPeriod, i) * Deviation;
         MaTDn[i] = MaBuffer[i] - iATR(NULL, 0, nPeriod, i);
       }  
      else if(iClose(NULL, 0, i) < MaBuffer[i])
       {
         MaTDn[i] = MaBuffer[i] - iATR(NULL, 0, nPeriod, i) * Deviation;
         MaTUp[i] = MaBuffer[i] + iATR(NULL, 0, nPeriod, i);
       } 
      else if(iClose(NULL, 0, i) == MaBuffer[i])
       {
         MaTDn[i] = MaBuffer[i] - iATR(NULL, 0, nPeriod, i) * Deviation;
         MaTUp[i] = MaBuffer[i] + iATR(NULL, 0, nPeriod, i) * Deviation;
       }  
    }  
   //-----
   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 ---