-
Notifications
You must be signed in to change notification settings - Fork 2
/
UpDownBars.mq4
84 lines (74 loc) · 2.51 KB
/
UpDownBars.mq4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//+------------------------------------------------------------------+
//| UpDownBars.mq4 |
//| Copyright © 2011, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 1 // Number of buffers
#property indicator_color1 Red
extern int period = 20;
double UpDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0,UpDown);
SetIndexStyle (0,DRAW_HISTOGRAM);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if(Bars<=period) return(0);
int i;
int counted_bars=IndicatorCounted();
double bar, ups, downs, upsDivide, downsDivide;
int upsCount, downsCount;
int limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(i=0; i<limit; i++)
{
ups = 0;
downs = 0;
bar = 0;
upsCount = 0;
downsCount = 0;
upsDivide=0;
downsDivide=0;
for(int j=period;j>=0;j--)
{
bar=(Close[i+j]-Open[i+j])*100000;
if(bar>0)
{
ups+=(MathSqrt(bar)*((period+1-j)));
upsCount++;
}
if(bar<0)
{
downs+=(MathSqrt(-bar)*((period+1-j)));
downsCount++;
}
}
if(upsCount!=0)
upsDivide = ups/upsCount;
if(downsCount!=0)
downsDivide = downs/downsCount;
UpDown[i]=NormalizeDouble(((upsDivide)-(downsDivide)),3);
}
return(0);
}
//+------------------------------------------------------------------+