Price Data Components
Indicators Used
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 Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---