-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathiPatrickDraw.mqh
170 lines (143 loc) · 4.68 KB
/
iPatrickDraw.mqh
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
//+------------------------------------------------------------------+
//| iPatrickDraw.mq5 |
//| GPL License|
//| Use at your own risk! Not a holy grail|
//+------------------------------------------------------------------+
#property copyright "GPL License"
/*
* Draw a line.
* @param name - name for the object.
* @param price - price line to create the object.
*/
void drawLine(const string name, const double price, const datetime time, const color line_color = clrRed)
{
ObjectCreate(0,name,OBJ_HLINE,0,time,price);
ObjectSetInteger(0,name,OBJPROP_COLOR,line_color);
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
}
/*
* Draw an object.
* @param name - name for the object.
* @param price - price line to create the object.
*/
void drawObject(const string name, const double price, const datetime time,
const ENUM_OBJECT objectType)
{
ObjectCreate(0,name,objectType,0,time,price);
ObjectSetInteger(0,name,OBJPROP_COLOR,clrGreen);
}
/*
* Move an object.
* @param name - name for the object.
* @param price - price line to create the object.
*/
void moveObject(const string name, const double price, const datetime time,
const ENUM_OBJECT objectType)
{
ObjectCreate(0,name,objectType,0,time,price);
ObjectSetInteger(0,name,OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);
}
/*
* Draw a buy / sell icon on the chart.
* @param name - name for the object.
* @param price - price line to create the object.
* @param orderTime - date to place this object.
* @param orderType - buy or sell icon for this object.
*/
void drawPurchase(const string name, const double price, const datetime orderTime,
const ENUM_ORDER_TYPE orderType)
{
color arrow_color = clrRed;
ENUM_OBJECT orderObject = OBJ_ARROW_BUY;
if (orderType == ORDER_TYPE_BUY)
{
orderObject = OBJ_ARROW_UP;
arrow_color = clrLightYellow;
}
else if (orderType == ORDER_TYPE_SELL)
{
orderObject = OBJ_ARROW_DOWN;
}
ObjectCreate(0,name,orderObject,0,orderTime,price);
ObjectSetInteger(0,name,OBJPROP_COLOR,arrow_color);
}
/*
* Draw a buy / sell icon on the chart.
* @param name - name for the object.
* @param price - price line to create the object.
* @param orderTime - date to place this object.
* @param orderType - buy or sell icon for this object.
*/
void drawBanner(const string label_name, const ENUM_ORDER_TYPE orderType)
{
int height= (int) ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0);
int width=(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
ObjectCreate(0,label_name,OBJ_LABEL,0,0,0);
//--- set X coordinate
ObjectSetInteger(0,label_name,OBJPROP_XDISTANCE,width-160);
//--- set Y coordinate
ObjectSetInteger(0,label_name,OBJPROP_YDISTANCE,10);
//--- define text string
ObjectSetString(0,label_name,OBJPROP_TEXT, label_name);
//--- define font
ObjectSetString(0,label_name,OBJPROP_FONT,"Arial");
//--- define font size
ObjectSetInteger(0,label_name,OBJPROP_FONTSIZE,40);
//--- draw it on the chart
if(orderType == ORDER_TYPE_BUY)
{
//--- define text color
ObjectSetInteger(0,label_name,OBJPROP_COLOR,clrGreen);
}
else if(orderType == ORDER_TYPE_BUY)
{
//--- define text color
ObjectSetInteger(0,label_name,OBJPROP_COLOR,clrRed);
}
ChartRedraw(0);
}
/*
* Draw label at x, y coordinate.
* @param label_name
* @param info
* @param x
* @param y
*/
void drawText(const string label_name, const string info, const int x, const int y)
{
ObjectCreate(0,label_name,OBJ_TEXT,0,0,0);
ObjectSetString(0,label_name,OBJPROP_TEXT, info);
//--- set X coordinate
ObjectSetInteger(0,label_name,OBJPROP_XDISTANCE,x);
//--- set Y coordinate
ObjectSetInteger(0,label_name,OBJPROP_YDISTANCE,y);
ChartRedraw(0);
} // end function
void drawMark(const string name, const datetime time, const double price, const string shortname)
{
if(ObjectFind(0,name)< 0)
{
ObjectCreate(0, name, OBJ_TEXT, 0, time, price);
ObjectSetString(0, name, OBJPROP_TEXT, shortname);
ObjectSetString(0, name, OBJPROP_FONT, "Times New Roman");
}
}
/*
* Display comments and print string.
* @param msg
*/
void debug(const string &msg[])
{
string message = "";
for(int i=0;i<ArraySize(msg);i++)
{
message = message + msg[i] +"\n";
}
Comment(message);
}
string getName(string aName, datetime timeshift)
{
return(aName + DoubleToString(timeshift, 0));
}