Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
Dist Ma
//+------------------------------------------------------------------+
//| Detrended Price Oscillator.mq4 |
//| Ramdass - Conversion only |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#property indicator_level1 500
#property indicator_levelcolor Red
//----
extern int x_prd = 800;
extern int CountBars = 15000;
//---- buffers
double dpo[];
double dpo1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, dpo);
//---- name for DataWindow and indicator subwindow label
short_name = "DPO(" + x_prd + ")";
IndicatorShortName(short_name);
SetIndexLabel(0, short_name);
//----
if(CountBars >= Bars)
CountBars = Bars;
SetIndexDrawBegin(0, Bars - CountBars + x_prd + 1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| DPO |
//+------------------------------------------------------------------+
int start()
{
int i, counted_bars=IndicatorCounted();
double t_prd, MA, count, dir;
//----
if(Bars <= x_prd)
return(0);
//---- initial zero
if(counted_bars < x_prd)
{
for(i = 1; i <= x_prd; i++)
dpo[CountBars-i] = 0.0;
}
//----
i = CountBars - x_prd - 1;
t_prd = x_prd / 2 + 1;
//----
while(i >= 0)
{
MA=iMA(NULL,0,x_prd,0,MODE_SMA,PRICE_CLOSE,i);
if (Close[i] > MA && Close[i+1] < MA || Close[i] < MA && Close[i+1] > MA )
count = 0;
if (Close[i] < MA )
count=count+1;
else count=0;
if (Close[i] > MA)
count = count +1;
dpo[i] = count;
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
---