-
Notifications
You must be signed in to change notification settings - Fork 2
/
#!DivStochv5.mq4
138 lines (122 loc) · 4.15 KB
/
#!DivStochv5.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
//+------------------------------------------------------------------+
//| #!DivStochv5.mq4 |
//| Copyright @2011, Rockyhoangdn |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "Copyright @2011, Rockyhoangdn"
#property link "[email protected]"
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 DarkGreen
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 DeepPink
#property indicator_color5 Yellow
#property indicator_color6 Blue
#property indicator_color7 Red
#property indicator_color8 Lime
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 3
#property indicator_width4 3
#property indicator_width5 2
#property indicator_width6 2
#property indicator_width7 3
#property indicator_width8 3
#property indicator_level4 60
#property indicator_level1 70
#property indicator_level2 80
#property indicator_level3 90
#property indicator_levelcolor Gray
#property indicator_minimum 50
#property indicator_maximum 100
extern int StochPeriod=20;
extern int Sensitive=5;
double overbought_value=99.9;
double oversold_value=99.9;
double buf[];
double bufinv[];
double mabuf[];
double mabufinv[];
double buf2[];
double overbought[];
double oversold[];
double shortentry[];
double longentry[];
int init()
{
SetIndexBuffer(0,buf);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexLabel(0,"buf");
SetIndexBuffer(1,bufinv);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexLabel(1,"bufinv");
SetIndexBuffer(2,overbought);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexLabel(2,"Overbought");
SetIndexBuffer(3,oversold);
SetIndexStyle(3,DRAW_HISTOGRAM);
SetIndexLabel(3,"Oversold");
SetIndexBuffer(4,mabuf);
SetIndexStyle(4,DRAW_LINE);
SetIndexLabel(4,"Mabuf");
SetIndexBuffer(5,mabufinv);
SetIndexStyle(5,DRAW_LINE);
SetIndexLabel(5,"Mabufinv");
SetIndexBuffer(6,shortentry);
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,252);
SetIndexLabel(6,"Shortentry");
SetIndexBuffer(7,longentry);
SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(7,252);
SetIndexLabel(7,"Longentry");
IndicatorShortName("Div-Stochv5 - [email protected]");
return(0);
}
int start()
{
int limit=Bars;
ArrayResize(buf2,limit);
ArraySetAsSeries(buf2,true);
for(int i=0; i<limit; i++)
{
buf2[i]=(iStochastic(NULL,0,StochPeriod,3,3,MODE_EMA,1,MODE_MAIN,i)+
iStochastic(NULL,0,StochPeriod*2.5,3,3,MODE_EMA,1,MODE_MAIN,i)*2.5+
iStochastic(NULL,0,StochPeriod*5,3,3,MODE_EMA,1,MODE_MAIN,i)*5+
iStochastic(NULL,0,StochPeriod*10,3,3,MODE_EMA,1,MODE_MAIN,i)*10
)/18.5;
}
for(i=0; i<limit; i++)
{
buf[i]=iMAOnArray(buf2,limit,1,0,MODE_EMA,i);
bufinv[i]=100-buf[i];
if(buf[i] >= overbought_value) overbought[i]=buf[i];
if(bufinv[i] >= oversold_value) oversold[i]=bufinv[i];
}
for(int ii=0; ii<limit; ii++)
{
mabuf[ii]=iMAOnArray(buf,limit,Sensitive,0,MODE_LWMA,ii);
mabufinv[ii]=iMAOnArray(bufinv,limit,Sensitive,0,MODE_LWMA,ii);
}
for(int iii=0; iii<limit; iii++)
{
if((buf[iii+1] >= overbought_value && buf[iii] <= mabuf[iii])
||(buf[iii+2] >= overbought_value && buf[iii] <= mabuf[iii])
||(buf[iii+3] >= overbought_value && buf[iii] <= mabuf[iii])
)
{
shortentry[iii] = buf[iii];
}
else shortentry[iii] =0;
if((bufinv[iii+1] >= overbought_value && bufinv[iii] <= mabufinv[iii])
||(bufinv[iii+2] >= overbought_value && bufinv[iii] <= mabufinv[iii])
||(bufinv[iii+3] >= overbought_value && bufinv[iii] <= mabufinv[iii])
)
{
longentry[iii] = bufinv[iii];
}
else longentry[iii] =0;
}
return(0);
}