-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFractalLevels.mq4
167 lines (138 loc) · 4.93 KB
/
FractalLevels.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//+------------------------------------------------------------------+
//| iFractals.mq4 |
//| Copyright © 2008, lotos4u |
//| lotos4u@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, lotos4u"
#property link "lotos4u@gmail.com"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_width1 4
#property indicator_width2 4
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Gold
#property indicator_color4 Gold
#property indicator_color5 White
#property indicator_color6 White
extern int LeftBars = 3;
extern int RightBars = 3;
double LineUpBuffer1[];
double LineDownBuffer2[];
double ArrowUpBuffer3[];
double ArrowDownBuffer4[];
double ArrowBreakUpBuffer5[];
double ArrowBreakDownBuffer6[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_LINE);
SetIndexArrow(0, 158);
SetIndexBuffer(0, LineUpBuffer1);
SetIndexEmptyValue(0, 0.0);
SetIndexLabel(0, "Ôðàêòàëüíîå ñîïðîòèâëåíèå");
SetIndexStyle(1, DRAW_LINE);
SetIndexArrow(1, 158);
SetIndexBuffer(1, LineDownBuffer2);
SetIndexEmptyValue(1, 0.0);
SetIndexLabel(1, "Ôðàêòàëüíàÿ ïîääåðæêà");
SetIndexStyle(2, DRAW_ARROW);
SetIndexArrow(2, 119);
//SetIndexArrow(2, 217);
SetIndexBuffer(2, ArrowUpBuffer3);
SetIndexEmptyValue(2, 0.0);
SetIndexLabel(2, "Ôðàêòàë ÂÅÐÕ");
SetIndexStyle(3, DRAW_ARROW);
SetIndexArrow(3, 119);
//SetIndexArrow(3, 218);
SetIndexBuffer(3, ArrowDownBuffer4);
SetIndexEmptyValue(3, 0.0);
SetIndexLabel(3, "Ôðàêòàë ÂÍÈÇ");
SetIndexStyle(4, DRAW_ARROW);
SetIndexArrow(4, 119);
//SetIndexArrow(4, 217);
SetIndexBuffer(4, ArrowBreakUpBuffer5);
SetIndexEmptyValue(4, 0.0);
SetIndexLabel(4, "Ïðîáîé ÂÂÅÐÕ");
SetIndexStyle(5, DRAW_ARROW);
SetIndexArrow(5, 119);
//SetIndexArrow(5, 218);
SetIndexBuffer(5, ArrowBreakDownBuffer6);
SetIndexEmptyValue(5, 0.0);
SetIndexLabel(5, "Ïðîáîé ÂÍÈÇ");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit(){return(0);}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;
if(counted_bars==0) limit-=1+MathMax(LeftBars,RightBars);
for(int i = limit-1; i >= 0; i--)
{
LineUpBuffer1[i] = isFractalUp(i, LeftBars, RightBars,limit);
if(LineUpBuffer1[i] == 0)
LineUpBuffer1[i] = LineUpBuffer1[i+1];
else
ArrowUpBuffer3[i] = LineUpBuffer1[i];
LineDownBuffer2[i] = isFractalDown(i, LeftBars, RightBars,limit);
if(LineDownBuffer2[i] == 0)
LineDownBuffer2[i] = LineDownBuffer2[i+1];
else
ArrowDownBuffer4[i] = LineDownBuffer2[i];
if(Close[i] < LineDownBuffer2[i] && Close[i+1] >= LineDownBuffer2[i+1])
ArrowBreakDownBuffer6[i] = Close[i];
}
//LineUpBuffer1[-1] = LineUpBuffer1[0];
//LineDownBuffer2[-1] = LineDownBuffer2[0];
return(0);
}
double isFractalUp(int index, int lBars, int rBars, int maxind)
{
int left = lBars, right = rBars;
double max = High[index]; //Ïðèíèìàåì çà ìàêñèìóì çíà÷åíèå Õàÿ èññëåäóåìîãî áàðà
for(int i = index - right; i <= (index + left); i++)
{
if (i<0 || i>maxind) return(0);
if(!(High[i] > 0.0))return(0);
if(max < High[i] && i != index)
{
if(max < High[i]) return(0);
if(MathAbs(i - index) > 1) return(0);
}
}
return(max);
}
double isFractalDown(int index, int lBars, int rBars, int maxind)
{
int left = lBars, right = rBars;
double min = Low[index], test;
for(int i = index - right; i <= (index + left); i++)
{
if (i<0 || i>maxind) return(0);
if(!(Low[i] > 0.0))return(0);
//if(min >= Low[i] && i != index)
if(min > Low[i] && i != index)
{
if(min > Low[i])
return(0);
if(MathAbs(i - index) > 1)
return(0);
}
}
return(min);
}