Author: Copyright � 2010, WUCIWUG
Price Data Components
Series array that contains open time of each bar
Indicators Used
Indicator of the average true rangeMoving average indicator
0 Views
0 Downloads
0 Favorites
Volt
#property copyright "Copyright © 2010, WUCIWUG"
#property link      "wuciwu@gmail.com"

extern int     ATRPeriod = 14;
extern int     AvgPeriod = 20;
extern int     Smoothing = 15;

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Red
#property indicator_color2 White

double ATR[];
double AvgATR[];
double Differ[];
double Smoothed[];

int init()
{
   IndicatorBuffers(4);
   
   SetIndexBuffer(0, Differ);
   SetIndexBuffer(1, Smoothed);
   SetIndexBuffer(2, ATR);
   SetIndexBuffer(3, AvgATR);
   
   return(0);
}

int start()
{
   int toCount = MathMin(Bars, Bars - IndicatorCounted() + 1);
   
   for (int i = toCount - 1; i >= 0; i--)
   {
      ATR[i] = iATR(Symbol(), 0, ATRPeriod, i);
      if (ATR[i] == 0) ATR[i] = EMPTY_VALUE;
   }
   
   for (i = toCount - 1; i >= 0; i--)
   {
      AvgATR[i] = EMPTY_VALUE;
      double sum = 0;
      int dayShift = iBarShift(Symbol(), PERIOD_D1, Time[i], true);
      
      if (dayShift != -1 && ATR[i] != EMPTY_VALUE)
      {
         int offset = Time[i] - iTime(Symbol(), PERIOD_D1, dayShift);
         double lastValue = ATR[i];
         
         for (int j = 0; j < AvgPeriod; j++)
         {
            int elementShift = iBarShift(Symbol(), 0, iTime(Symbol(), PERIOD_D1, dayShift + j) + offset, true);
            if (elementShift == -1 || ATR[elementShift] == EMPTY_VALUE)
            {
               sum += lastValue;
            }
            else
            {
               sum += ATR[elementShift];
               lastValue = ATR[elementShift];
            }
         }
         AvgATR[i] = sum/AvgPeriod;
      }
   }
   
   for (i = toCount - 1; i >= 0; i--)
   {
      if (ATR[i] != EMPTY_VALUE && AvgATR[i] != EMPTY_VALUE)
      {
         Differ[i] = ATR[i] - AvgATR[i];
      }
      else
      {
         Differ[i] = 0;
      }
   }

   for (i = toCount - 1; i >= 0; i--)
   {
      Smoothed[i] = iMAOnArray(Differ, 0, Smoothing, 0, MODE_SMA, i);
   }
   
   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 ---