-
Notifications
You must be signed in to change notification settings - Fork 2
/
watr.mq4
130 lines (128 loc) · 5.14 KB
/
watr.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//+------------------------------------------------------------------+
//| WATR.mq4 |
//| Written WizardSerg under article konkop in |
//| "Modern trading" #4/2001 |
//| http://www.wizardserg.inweb.ru |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "Written WizardSerg under article konkop in <Modern trading> #4/2001"
#property link "http://www.wizardserg.inweb.ru"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Coral
#property indicator_color2 DodgerBlue
//---- input parameters
extern int WATR_K = 10;
extern double WATR_M = 4.0;
extern int ATR = 21;
//---- buffers
double ExtMapBufferUp[];
double ExtMapBufferDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
SetIndexBuffer(0, ExtMapBufferUp);
ArraySetAsSeries(ExtMapBufferUp, true);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1, ExtMapBufferDown);
ArraySetAsSeries(ExtMapBufferDown, true);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
IndicatorShortName("WATR(" + WATR_K + ", " + WATR_M + ")");
SetIndexLabel(0, "WATR_Up");
SetIndexLabel(1, "WATR_Dn");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator function |
//+------------------------------------------------------------------+
bool AntiTrendBar(int i)
{
bool res = (TrendUp(i) && (Close[i] < Open[i])) ||
(!TrendUp(i) && (Close[i] > Open[i]));
return(res);
}
//+------------------------------------------------------------------+
//| Custom indicator function |
//+------------------------------------------------------------------+
double CalcIndicValue(int i, bool trend)
{
double res = Close[i];
if(trend)
res -= (WATR_K*Point + WATR_M*iATR(NULL, 0, ATR, i));
else
res += (WATR_K*Point + WATR_M*iATR(NULL, 0, ATR, i));
return(res);
}
//+------------------------------------------------------------------+
//| Custom indicator function |
//+------------------------------------------------------------------+
bool TrendUp(int i)
{
return((Close[i+1] > ExtMapBufferUp[i+1]) &&
(ExtMapBufferUp[i+1] != EMPTY_VALUE));
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
//---- ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
//---- ïåðâîå çíà÷åíèå èíäèêàòîðà == öåíå-1 point,
// òî åñòü ñ÷èòàåò òðåíä âîñõîäÿùèì
ExtMapBufferUp[Bars] = Close[Bars] - WATR_K*Point;
// limit = (counted_bars > 0) ? (Bars - counted_bars) : (Bars - 1);
limit = Bars - counted_bars;
//---- îñíîâíîé öèêë
for(int i = limit; i >= 0; i--)
{
if(AntiTrendBar(i))
{
ExtMapBufferUp[i] = ExtMapBufferUp[i+1];
ExtMapBufferDown[i] = ExtMapBufferDown[i+1];
}
else
{
if(TrendUp(i))
{
ExtMapBufferUp[i] = CalcIndicValue(i, true);
if(ExtMapBufferUp[i] < ExtMapBufferUp[i+1])
ExtMapBufferUp[i] = ExtMapBufferUp[i+1];
ExtMapBufferDown[i] = EMPTY_VALUE;
}
else
{
ExtMapBufferDown[i] = CalcIndicValue(i, false);
if(ExtMapBufferDown[i] > ExtMapBufferDown[i+1])
ExtMapBufferDown[i] = ExtMapBufferDown[i+1];
ExtMapBufferUp[i] = EMPTY_VALUE;
}
}
// ïåðåñå÷åíèÿ ñ öåíîé
if(TrendUp(i) && (Close[i] < ExtMapBufferUp[i]))
{
ExtMapBufferDown[i] = CalcIndicValue(i, false);
ExtMapBufferUp[i] = EMPTY_VALUE;
}
if((!TrendUp(i)) && (Close[i] > ExtMapBufferDown[i]))
{
ExtMapBufferUp[i] = CalcIndicValue(i, true);
ExtMapBufferDown[i] = EMPTY_VALUE;
}
}
return(0);
}
//+------------------------------------------------------------------+