-
Notifications
You must be signed in to change notification settings - Fork 1
/
Show Pips.mq5
272 lines (255 loc) · 10.5 KB
/
Show Pips.mq5
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//+------------------------------------------------------------------+
//| Show Pips.mq4 |
//| Copyright 2017, TPSproTrading |
//| http://www.tpsprotrading.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, TPSproTrading"
#property link "https://www.tpsprotrading.com"
#property version "2.2"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Parameters |
//+------------------------------------------------------------------+
enum ENUM_SHOW_TYPE
{
a = 0, // Follow the price
b = 1, // As comment
c = 2, // In selected corner of the screen
};
input ENUM_SHOW_TYPE
show_type=0; // Type of appearance
input ENUM_BASE_CORNER
corner=CORNER_RIGHT_LOWER; // Graph corner for attachment
input bool show_profit = false; // Show profit?
input bool show_perc = false; // Show profit in percents?
input bool show_spread = true; // Show spread?
input bool show_time = true; // Show time to bar closure?
input color colortext = clrBlack; // Text color
input color ecProfit = clrBlue; // Profit color
input color ecLoss = clrRed; // Loss color
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
enum ENUM_SEPARATOR
{
d = 124, // |
e = 47, // /
f = 46, // .
g = 92, // \
h = 35, // #
};
extern ENUM_SEPARATOR
separator = 124; // Separator
extern int coord_y = 12; // Y coordinate
extern int indent = 5; // Indent in bars
extern int text_size = 8; // Font size
extern string text_font = "Calibry"; // Font
string name_1 = "TPSpro_SMT";
string text_1 = "";
double n = 1.0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
int _dig=(int)SymbolInfoInteger(Symbol(),SYMBOL_DIGITS);
if(_dig == 3|| _dig == 5) n *= 10;
//--- indicator buffers mapping
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
ObjectDelete(0,name_1);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
double tu = 0.0, tp = 0.0, tr = 0.0,
sp = (double)SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
string _sp = "", _m = "", _s = "";
string sep = "";
StringConcatenate(sep," ",CharToString(char(separator))," ");
if(AccountInfoDouble(ACCOUNT_BALANCE)==0.0)
{
text_1="";
}
else
{
tu = GetProfitOpenPosInPoint();
tp = GetProfitOpenPos();
tr = tp * 100.0 / AccountInfoDouble(ACCOUNT_BALANCE);
//Comment(tu, " ", tp, " ", tr, " ", AccountInfoDouble(ACCOUNT_BALANCE));
StringConcatenate(text_1,DoubleToString(tu,1)," pips");
if(show_profit) StringConcatenate(text_1,text_1,sep,DoubleToString(tp,2)," ",AccountInfoString(ACCOUNT_CURRENCY));
if(show_perc) StringConcatenate(text_1,text_1,sep,DoubleToString(tr,1),"%");
}
//--- Time to bar expiry
int m = int(SeriesInfoInteger(Symbol(), 0, SERIES_LASTBAR_DATE) + PeriodSeconds() - TimeCurrent());
int s = m%60;
m=(m-s)/60;
if(m < 10) _m = "0";
if(s < 10) _s = "0";
if(sp < 10) _sp = "..";
else if(sp < 100) _sp = ".";
if(show_spread)
{
if(AccountInfoDouble(ACCOUNT_BALANCE)==0.0)
StringConcatenate(text_1,text_1,DoubleToString(sp,0),_sp);
else
StringConcatenate(text_1,text_1,sep,DoubleToString(sp,0),_sp);
}
if(show_time)
{
if(AccountInfoDouble(ACCOUNT_BALANCE)==0.0 && !show_spread)
StringConcatenate(text_1,text_1,_m,DoubleToString(m,0),":",_s,DoubleToString(s,0)); // Next bar in
else
StringConcatenate(text_1,text_1,sep,_m,DoubleToString(m,0),":",_s,DoubleToString(s,0)); // Next bar in
}
if(show_type==0)
SetText(name_1,text_1,ColorOnSign(tp),TimeCurrent(),SymbolInfoDouble(Symbol(),SYMBOL_BID),text_size);
if(show_type==1)
Comment(text_1);
if(show_type==2)
SetLabel(name_1,text_1,ColorOnSign(tp),3,coord_y,corner,text_size);
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetProfitOpenPos(int mn=-1)
{
int orders = PositionsTotal();
double pr = 0.0;
for(int i=0; i<orders; i++)
{
ResetLastError();
string symbol=PositionGetSymbol(i);
if(symbol==Symbol())
{
if(mn<0 || OrderGetInteger(ORDER_MAGIC)==mn)
{
pr+=PositionGetDouble(POSITION_PROFIT)+PositionGetDouble(POSITION_SWAP);
}
}
}
return (pr);
}
//+----------------------------------------------------------------------------+
//| Author : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Version : 01.08.2008 |
//| Description : Returns the total profit of open items in points |
//+----------------------------------------------------------------------------+
//| Parameters: |
//| sy - name of the tool ("" - any character, |
//| NULL - the current character) |
//| op - operation (-1 - any position) |
//| mn - MagicNumber (-1 - any magic) |
//+----------------------------------------------------------------------------+
double GetProfitOpenPosInPoint(int op=-1,int mn=-1)
{
double pr=0.0;
for(int i=0; i<PositionsTotal(); i++)
{
ResetLastError();
string symbol=PositionGetSymbol(i);
if(symbol==Symbol())
{
ulong type = OrderGetInteger(ORDER_TYPE),
magic = OrderGetInteger(ORDER_MAGIC);
if(op<0 || type==op)
{
if(mn<0 || magic==mn)
{
if(type==ORDER_TYPE_BUY)
{
pr+=(PositionGetDouble(POSITION_PROFIT)/PositionGetDouble(POSITION_VOLUME)/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE))/n;
}
if(type==ORDER_TYPE_SELL)
{
pr+=(PositionGetDouble(POSITION_PROFIT)/PositionGetDouble(POSITION_VOLUME)/SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE))/n;
}
}
}
}
}
return (pr);
}
//+------------------------------------------------------------------+
//| Set text |
//+------------------------------------------------------------------+
bool SetText(string nm,string tx,color cl,datetime time,double price,int fs)
{
time+=indent*PeriodSeconds();
ResetLastError();
//--- Create object "Text"
if(ObjectFind(0,nm)<0)
ObjectCreate(0,nm,OBJ_TEXT,0,time,price);
ObjectMove(0,nm,0,time,price);
ObjectSetString(0,nm,OBJPROP_TEXT,tx);
ObjectSetString(0,nm,OBJPROP_FONT,text_font);
ObjectSetInteger(0,nm,OBJPROP_FONTSIZE,fs);
ObjectSetDouble(0,nm,OBJPROP_ANGLE,0.0);
ObjectSetInteger(0,nm,OBJPROP_ANCHOR,ANCHOR_LEFT_LOWER);
ObjectSetInteger(0,nm,OBJPROP_COLOR,cl);
ObjectSetInteger(0,nm,OBJPROP_BACK,false);
ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,nm,OBJPROP_SELECTED,false);
ObjectSetInteger(0,nm,OBJPROP_HIDDEN,true);
return (true);
}
//+------------------------------------------------------------------+
//| Set label |
//+------------------------------------------------------------------+
void SetLabel(string nm,string tx,color cl,int xd,int yd,int cr,int fs)
{
ResetLastError();
//--- Create object "Label"
if(ObjectFind(0,nm)<0)
ObjectCreate(0,nm,OBJ_LABEL,0,0,0);
ObjectSetString(0,nm,OBJPROP_TEXT,tx);
ObjectSetInteger(0,nm,OBJPROP_COLOR,cl);
ObjectSetInteger(0,nm,OBJPROP_XDISTANCE,xd);
ObjectSetInteger(0,nm,OBJPROP_YDISTANCE,yd);
ObjectSetInteger(0,nm,OBJPROP_CORNER,cr);
ObjectSetInteger(0,nm,OBJPROP_FONTSIZE,fs);
ObjectSetInteger(0,nm,OBJPROP_HIDDEN,true);
if(cr==CORNER_RIGHT_UPPER || cr==CORNER_RIGHT_LOWER)
ObjectSetInteger(0,nm,OBJPROP_ANCHOR,ANCHOR_RIGHT);
}
//+------------------------------------------------------------------+
//| Returns the color by the sign of a number |
//+------------------------------------------------------------------+
color ColorOnSign(double nu)
{
color lcColor=colortext;
if(nu > 0) lcColor = ecProfit;
if(nu < 0) lcColor = ecLoss;
return(lcColor);
}
//+------------------------------------------------------------------+