Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
Range_Rider
#property copyright "Copyright © 2013, Langouste"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int AtrPeriod1=2;
extern int AtrPeriod2=7;
//---- buffers
double AtrBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- 1 additional buffer used for counting.
IndicatorBuffers(2);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,AtrBuffer);
SetIndexBuffer(1,TempBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="Range Rider("+AtrPeriod1+ ", " +AtrPeriod2+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,AtrPeriod2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Average True Range |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
//----
if(Bars<=AtrPeriod2) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=AtrPeriod2;i++) AtrBuffer[Bars-i]=0.0;
//----
i=Bars-counted_bars-1;
while(i>=0)
{
double high=High[i];
double low =Low[i];
if(i==Bars-1) TempBuffer[i]=high-low;
else
{
double prevclose=Close[i+1];
TempBuffer[i]=MathMax(high,prevclose)-MathMin(low,prevclose);
}
i--;
}
//----
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
for(i=0; i<limit; i++)
{
if (iMAOnArray(TempBuffer,Bars,AtrPeriod2,0,MODE_SMA,i)!=0)
AtrBuffer[i]=(iMAOnArray(TempBuffer,Bars,AtrPeriod1,0,MODE_SMA,i)/iMAOnArray(TempBuffer,Bars,AtrPeriod2,0,MODE_SMA,i))*100;
}
//----
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
---