-
Notifications
You must be signed in to change notification settings - Fork 1
/
PZ_PivotPoints.mq4
201 lines (175 loc) · 7.47 KB
/
PZ_PivotPoints.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// ````` +yys. ````````````
// yNNNNNNmds: dNNm: `++/ `mNNNNNNNNNNN`
// yNNNdyhmNNNo .://:. -//:` `--- -:/:. `hNNd--- syyyyydNNNNy .://:- `--- .:/. .://:.
// yNNNs sNNNd +mNNNNNNmo` mNNN: /NNNymNNNNNh. ymNNNNNNd +mNNm/ +dNNNNNNms` :NNNohNNN: +dNNNNNNms`
// yNNNhosmNNNo sNNNh--sNNNh mNNN: /NNNNs:/mNNNs :sNNNd::- .hNNNh. oNNNh.`:mNNh :NNNNmyss`sNNNh:-sNNNd`
// yNNNNNNNNh/ NNNN: .NNNN- mNNN: /NNNm sNNNy +NNNh /mNNm+ mNNNmmmmNNNm :NNNN. mNNN/ `NNNN:
// yNNNy--.` mNNN+ -NNNN. mNNN: /NNNd sNNNy +NNNh `sNNNd- dNNNy//////: :NNNN dNNN+ .NNNN-
// yNNNs :mNNmysmNNN+ mNNN: /NNNd sNNNy /NNNNhyd `dNNNNmdddddd--mNNNyoosyd- :NNNN -mNNmysmNNNo
// sddd+ `+ydmmdho. hddd- :dddy oddds +hmmmdy .dddddddddddd. `/ydmmmdhs` -dddd `+ydmmdho-
//
// ---------------------------------------------------------------------------------------------------------------
// File | PZ_PivotPoints.mq4
// Description | Draws Pivot Points in relation to the desired timeframe.
// Copyright | Point Zero Trading Solutions
// Website | http://www.pointzero-trading.com
// ---------------------------------------------------------------------------------------------------------------
#property copyright "Copyright © Pointzero-trading.com"
#property link "http://www.pointzero-trading.com"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 DeepSkyBlue
#property indicator_color5 DeepSkyBlue
#property indicator_color6 DeepSkyBlue
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_DASH
#property indicator_style3 STYLE_DOT
#property indicator_style4 STYLE_SOLID
#property indicator_style5 STYLE_DASH
#property indicator_style6 STYLE_DOT
//---- constants
#define ShortName "PZ Pivot Points"
#define OLabel "PZPVLabel"
#define Shift 1
//-- Buffers
double FextMapBuffer1[];
double FextMapBuffer2[];
double FextMapBuffer3[];
double FextMapBuffer4[];
double FextMapBuffer5[];
double FextMapBuffer6[];
//-- Parameters
extern string TF_Ex = "---- Pivot Point Timeframe";
extern string FromTimeFrame = "D1";
extern string LB_Ex = "---- Labels";
extern bool DisplayLabels = true;
extern color ResistanceLabel = Red;
extern color SupportLabel = DodgerBlue;
extern int LabelFontSize = 10;
//---- Internal
int FTimeFrame = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//|------------------------------------------------------------------|
int init()
{
// Draw
SetIndexStyle(0,DRAW_LINE); // Resistance 1
SetIndexStyle(1,DRAW_LINE); // Resistance 2
SetIndexStyle(2,DRAW_LINE); // Resistance 3
SetIndexStyle(3,DRAW_LINE); // Support 1
SetIndexStyle(4,DRAW_LINE); // Support 2
SetIndexStyle(5,DRAW_LINE); // Support 3
// Bufers
SetIndexBuffer(0,FextMapBuffer1);
SetIndexBuffer(1,FextMapBuffer2);
SetIndexBuffer(2,FextMapBuffer3);
SetIndexBuffer(3,FextMapBuffer4);
SetIndexBuffer(4,FextMapBuffer5);
SetIndexBuffer(5,FextMapBuffer6);
// Delete objects
DeleteObjects();
// Pick the right timeframe
if(FromTimeFrame == "MN1") FTimeFrame = PERIOD_MN1; else
if(FromTimeFrame == "W1") FTimeFrame = PERIOD_W1; else
if(FromTimeFrame == "D1") FTimeFrame = PERIOD_D1; else
if(FromTimeFrame == "H4") FTimeFrame = PERIOD_H4; else
if(FromTimeFrame == "H1") FTimeFrame = PERIOD_H1; else
if(FromTimeFrame == "M30") FTimeFrame = PERIOD_M30; else
if(FromTimeFrame == "M15") FTimeFrame = PERIOD_M15; else
if(FromTimeFrame == "M5") FTimeFrame = PERIOD_M5; else
if(FromTimeFrame == "M1") FTimeFrame = PERIOD_M1; else
FTimeFrame = PERIOD_D1;
// Name and Hi!
IndicatorShortName(ShortName);
Comment("Copyright © http://www.pointzero-trading.com");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int DeleteObjects()
{
int obj_total=ObjectsTotal();
for(int i = obj_total - 1; i >= 0; i--)
{
string label = ObjectName(i);
if(StringFind(label, OLabel) == -1) continue;
ObjectDelete(label);
}
return(0);
}
int deinit()
{
Comment("Copyright © http://www.pointzero-trading.com");
DeleteObjects();
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
// Start, limit, etc..
int start = 1;
int limit;
int counted_bars = IndicatorCounted();
// nothing else to do?
if(counted_bars < 0)
return(-1);
// do not check repeated bars
limit = Bars - 1 - counted_bars;
// Only for inferior timeframes!
if(Period() >= FTimeFrame) return(0);
// Iteration
for(int pos = limit; pos >= start; pos--)
{
// Daily shift to use
int dshift = iBarShift(Symbol(), FTimeFrame, Time[pos], false);
// High, low, close and open
double HIGH = iHigh(Symbol(), FTimeFrame, dshift+1);
double LOW = iLow(Symbol(), FTimeFrame, dshift+1);
double CLOSE = iClose(Symbol(), FTimeFrame, dshift+1);
double OPEN = iOpen(Symbol(), FTimeFrame, dshift+1);
// Pivot Point
double pv = (HIGH + LOW + CLOSE) / 3;
// Calcuations
FextMapBuffer1[pos] = (2 * pv) - LOW; // R1
FextMapBuffer4[pos] = (2 * pv) - HIGH; // S1
FextMapBuffer2[pos] = (pv - FextMapBuffer4[pos]) + FextMapBuffer1[pos]; // R2
FextMapBuffer5[pos] = pv - (FextMapBuffer1[pos] - FextMapBuffer4[pos]); // S2
FextMapBuffer3[pos] = (pv - FextMapBuffer5[pos]) + FextMapBuffer2[pos]; // R3
FextMapBuffer6[pos] = pv - (FextMapBuffer2[pos] - FextMapBuffer5[pos]); // S3
}
// Draw labels
DrawLabel("R1", Shift, FextMapBuffer1[Shift], ResistanceLabel, 0);
DrawLabel("R2", Shift, FextMapBuffer2[Shift], ResistanceLabel, 0);
DrawLabel("R3", Shift, FextMapBuffer3[Shift], ResistanceLabel, 0);
DrawLabel("S1", Shift, FextMapBuffer4[Shift], SupportLabel, 0);
DrawLabel("S2", Shift, FextMapBuffer5[Shift], SupportLabel, 0);
DrawLabel("S3", Shift, FextMapBuffer6[Shift], SupportLabel, 0);
// Bye
return(0);
}
void DrawLabel(string text, int shift, double vPrice, color vcolor, int voffset)
{
// Time
datetime x1 = Time[shift];
// Bye if I don't need you
if(!DisplayLabels) return(0);
// Label
string label = OLabel +"-"+ text;
// If object exists, detroy it -we might be repainting-
if(ObjectFind(label) != -1) ObjectDelete(label);
ObjectCreate(label, OBJ_TEXT, 0, x1, vPrice);
ObjectSetText(label, text, LabelFontSize, "Tahoma", vcolor);
ObjectSet(label, OBJPROP_BACK, true);
}