-
Notifications
You must be signed in to change notification settings - Fork 21
/
TradeInfo.mq4
822 lines (653 loc) · 32.9 KB
/
TradeInfo.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
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
//+------------------------------------------------------------------+
//| TradeInfo.mq4 |
//| Copyright © 2016, Ice FX |
//| http://www.icefx.eu |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, Ice FX <http://www.icefx.eu>"
#property link "http://www.icefx.eu"
#property version "1.98"
#property strict
#property indicator_separate_window
#property indicator_buffers 0
input bool ShowProfitInfo = TRUE;
input bool ShowTodayRanges = TRUE;
input bool ShowRiskInfo = FALSE;
input bool ShowAccountOrderInfo = TRUE;
input int RiskStopLoss = 0;
input string RiskLevels = "1,5,10,20,40,50,60,80,100";
input bool OnlyAttachedSymbol = FALSE;
input int MagicNumber = -1;
input string CommentFilter = "";
input string StartDateFilter = "";
input int FontSize = 8;
input bool WhiteMode = False;
int windowIndex = 0;
string preCurrSign = "";
string postCurrSign = "";
double pip_multiplier = 1.0;
int daySeconds = 86400;
double MaxDD = 0,
MaxDDp = 0,
CurrentDD = 0,
CurrentDDp = 0;
datetime maxDDDay;
datetime startDateFilter = 0;
datetime LastDrawProfitInfo = 0;
string IndiName = "TradeInfo v1.9.8";
/******************* Version history ********************************
v1.9.8 - 2016.03.13
--------------------
- fixed 2-digits XAU
v1.9.7 - 2016.03.07
--------------------
- support 2-digits CFDs
v1.9.6 - 2015.12.30
--------------------
- show lots in profit info
v1.9.5 - 2015.05.28
--------------------
- Number round problem fixed
- Customizable risk levels. The value is a comma-separated string without percent sign. E.G.: 1,2,5,10,15
v1.9.4 - 2014.08.27
--------------------
- White background mode
v1.9.2 - 2013.11.13
--------------------
- Some percentage bug fixed
v1.9.1 - 2013.11.04
--------------------
- Some bug fixed
v1.9.0 - 2013.10.17
--------------------
- Added Estimated profit and max losses in pips
- StartDateFilter: beállítható a profitszámítás kezdõ idõpontja
- ShowRiskInfo default értéke false
- Show daily and monthly average gain
- ProfitInfo refresh only every 10 seconds
v1.8.4 - 2013.08.15
--------------------
- Added Daily Max DrawDown info
v1.8.3 - 2013.07.11
--------------------
- Added Leverage and Swap info
v1.8.2 - 2013.07.11
--------------------
- Fixed some bug in pip calculation logic
v1.8.1 - 2013.07.09
--------------------
- Fixed some bug in pip calculation logic
v1.8.0 - 2013.06.27
--------------------
- Added this week, last week, this month, last month range
***********************************************************************/
//+------------------------------------------------------------------+
int init() {
//+------------------------------------------------------------------+
IndicatorShortName(IndiName);
//DeleteAllObject();
SetPipMultiplier(Symbol());
setCurrency();
// Load today max DD from global
maxDDDay = getGlobalVar("TRADEINFO_DD_DAY", 0);
if (maxDDDay >= iTime(Symbol(), PERIOD_D1, 0))
{
MaxDD = getGlobalVar("TRADEINFO_MAXDD", 0);
MaxDDp = getGlobalVar("TRADEINFO_MAXDDP", 0);
} else {
maxDDDay = iTime(Symbol(), PERIOD_D1, 0);
MaxDD = 0;
MaxDDp = 0;
}
if (StartDateFilter != "")
startDateFilter = StrToTime(StartDateFilter);
return(0);
}
//+------------------------------------------------------------------+
int start() {
//+------------------------------------------------------------------+
DoWork();
return(0);
}
//+------------------------------------------------------------------+
void DoWork() {
//+------------------------------------------------------------------+
windowIndex = WindowFind(IndiName);
CalculateDailyDrawDown();
if (ShowAccountOrderInfo) DrawAccountInfo();
if (ShowAccountOrderInfo) DrawCurrentTrades();
if (ShowTodayRanges) DrawTodayRange();
if (ShowProfitInfo) DrawProfitHistory();
if (ShowRiskInfo) DrawRiskInfo();
DrawCopyright();
}
//+------------------------------------------------------------------+
int deinit() {
//+------------------------------------------------------------------+
DeleteAllObject();
return(0);
}
//+------------------------------------------------------------------+
void CalculateDailyDrawDown() {
//+------------------------------------------------------------------+
double balance = AccountBalance();
if (balance != 0)
{
CurrentDD = 0.0 - ( AccountMargin() + (AccountBalance() - AccountEquity()));
CurrentDDp = MathDiv(CurrentDD, balance) * 100.0;
if (CurrentDD < MaxDD || iTime(Symbol(), PERIOD_D1, 0) > maxDDDay)
{
MaxDD = CurrentDD;
MaxDDp = CurrentDDp;
maxDDDay = iTime(Symbol(), PERIOD_D1, 0);
// Save to Global
setGlobalVar("TRADEINFO_MAXDD", MaxDD);
setGlobalVar("TRADEINFO_MAXDDP", MaxDDp);
setGlobalVar("TRADEINFO_DD_DAY", maxDDDay);
}
}
}
//+------------------------------------------------------------------+
double ND(double value, int decimal = -1) {
//+------------------------------------------------------------------+
if (decimal == -1)
decimal = Digits();
return (NormalizeDouble(value, decimal));
}
//+------------------------------------------------------------------+
string CutAt(string& str, string sep) {
//+------------------------------------------------------------------+
string res = "";
int index = StringFind(str, sep, 0);
if (index != -1)
{
if (index > 0) res = StringSubstr(str, 0, index);
str = StringSubstr(str, index + StringLen(sep));
} else {
res = str;
str = "";
}
return(res);
}
//+------------------------------------------------------------------+
color levelColors[10] = {Lime, SpringGreen, SpringGreen, LawnGreen, Gold, Gold, DarkSalmon, Tomato, Tomato, FireBrick};
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void DrawRiskInfo() {
//+------------------------------------------------------------------+
SetPipMultiplier(Symbol());
if (RiskStopLoss > 0)
DrawText(1, 0, 0, "Order Risk (SL=" + RiskStopLoss + ")", WhiteMode?Black:White, FontSize);
else
DrawText(1, 0, 0, "Order Risk", WhiteMode?Black:White, FontSize);
DrawText(1, 1, 0, "-------------------", WhiteMode?Black:White, FontSize);
string levels = RiskLevels;
int i = 0;
while (StringLen(levels) > 0)
{
string c = StringTrimLeft(StringTrimRight(CutAt(levels, ",")));
double value = StringToDouble(c);
if (value != EMPTY_VALUE) {
color clr = levelColors[ArraySize(levelColors) - 1];
if ( i < ArraySize(levelColors))
clr = levelColors[i];
DrawText(1, i + 2, 0, StringConcatenate(value, "%: ", DTS(MM(value), 2) + " lot"), clr, FontSize);
i++;
}
}
}
//+------------------------------------------------------------------+
void DrawAccountInfo() {
//+------------------------------------------------------------------+
SetPipMultiplier(Symbol());
int row = 1;
string text;
int colWidth1 = 200;
color c = WhiteMode?DarkBlue:LightCyan;
text = StringConcatenate("Balance: ", MTS(AccountBalance()));
DrawText(0, row, 0, text, c, FontSize);
double eqPercent = 0;
if (AccountBalance() > 0)
eqPercent = MathDiv(AccountEquity(), AccountBalance() * 100.0);
text = StringConcatenate("Equity: ", MTS(AccountEquity()), " (", DTS(eqPercent, 2), "%)");
DrawText(0, row, colWidth1, text, c, FontSize);
row++;
double marginLevel = 0;
if (AccountMargin() > 0) marginLevel = MathDiv(AccountEquity(), AccountMargin() * 100.0);
text = StringConcatenate("Margin: ", DTS(AccountMargin(), 2), " (", DTS(marginLevel, 2), "%)");
DrawText(0, row, 0, text, c, FontSize);
if (AccountFreeMargin() < 0)
c = Red;
text = StringConcatenate("Free margin: ", DTS(AccountFreeMargin(), 2));
DrawText(0, row, colWidth1, text, c, FontSize);
row++;
c = WhiteMode?DarkBlue:LightCyan;
text = StringConcatenate("Leverage: 1:", AccountLeverage());
DrawText(0, row, 0, text, c, FontSize);
text = StringConcatenate("Swap Long: ", MTS(MarketInfo(Symbol(), MODE_SWAPLONG), 2), " Short: ", MTS(MarketInfo(Symbol(), MODE_SWAPSHORT), 2));
DrawText(0, row, colWidth1, text, c, FontSize);
row++;
DrawText(0, row, 0, "------------------------------------------------------------------", Gray, FontSize);
}
//+------------------------------------------------------------------+
bool IsValidOrder() {
//+------------------------------------------------------------------+
if (!OnlyAttachedSymbol || OrderSymbol() == Symbol())
if ( MagicNumber == -1 || MagicNumber == OrderMagicNumber() )
if (CommentFilter == "" || StringFind(OrderComment(), CommentFilter) != -1)
return(true);
return(false);
}
//+------------------------------------------------------------------+
void DrawCurrentTrades() {
//+------------------------------------------------------------------+
int buyCount, sellCount = 0;
double buyProfit, sellProfit, buyLot, sellLot, buyPip, sellPip = 0;
double slPip, tpPip;
double allTPPips, allSLPips = 0;
double maxLoss, maxProfit = 0;
color c = White;
string text = "";
int colWidth1 = 200;
for (int i = OrdersTotal() - 1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if ( IsValidOrder() )
{
slPip = 0;
tpPip = 0;
if (OrderType() == OP_BUY) {
buyCount++;
buyProfit += OrderProfit() + OrderSwap() + OrderCommission();
buyLot += OrderLots();
buyPip += point2pip(MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice(), OrderSymbol());
if (OrderStopLoss() > 0.0) slPip = point2pip(OrderOpenPrice() - OrderStopLoss(), OrderSymbol());
if (OrderTakeProfit() > 0.0) tpPip = point2pip(OrderTakeProfit() - OrderOpenPrice(), OrderSymbol());
} else if (OrderType() == OP_SELL) {
sellCount++;
sellProfit += OrderProfit() + OrderSwap() + OrderCommission();
sellLot += OrderLots();
sellPip += point2pip(OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_BID), OrderSymbol());
if (OrderStopLoss() > 0.0) slPip = point2pip(OrderStopLoss() - OrderOpenPrice(), OrderSymbol());
if (OrderTakeProfit() > 0.0) tpPip = point2pip(OrderOpenPrice() - OrderTakeProfit(), OrderSymbol());
}
if (slPip != 0) {
maxLoss -= pip2money(slPip, OrderLots(), OrderSymbol());
allSLPips -= slPip;
}
if (tpPip != 0) {
maxProfit += pip2money(tpPip, OrderLots(), OrderSymbol()) + OrderSwap() + OrderCommission();
allTPPips += tpPip;
}
}
SetPipMultiplier(Symbol());
int row = 5;
//Spread
double spread = MathDiv(MarketInfo(Symbol(), MODE_SPREAD), pip_multiplier);
if (spread < 3) c = WhiteMode?DarkGreen:LawnGreen; else c = Crimson;
text = StringConcatenate("Spread: ", DTS(spread, 2));
DrawText(0, row, 0, text, c, FontSize);
//Drawdown
if (CurrentDD < 0) c = WhiteMode?Red:LightPink; else if (CurrentDD == 0.0) c = WhiteMode?Black:White; else c = WhiteMode?DarkGreen:LawnGreen;
text = StringConcatenate("Current DD: ", DTS(CurrentDD, 2), " (" + DTS(CurrentDDp, 2), "%)");
DrawText(0, row, colWidth1, text, c, FontSize);
row++;
//Max daily Drawdown
if (MaxDD < 0) c = WhiteMode?Red:LightPink; else if (MaxDD == 0.0) c = WhiteMode?Black:White; else c = WhiteMode?DarkGreen:LawnGreen;
text = StringConcatenate("Daily Max DD: ", DTS(MaxDD, 2), " (" + DTS(MaxDDp, 2), "%)");
DrawText(0, row, colWidth1, text, c, FontSize);
row++;
//Max loss + profit
if (maxProfit < 0) c = FireBrick; else if (maxProfit > 0) c = WhiteMode?DarkGreen:LawnGreen; else c = WhiteMode?Black:White;
text = StringConcatenate("Est. profit: ", MTS(maxProfit), " (", DTS(allTPPips, 1), " pips)");
DrawText(0, row, 0, text, c, FontSize);
if (maxLoss < 0) c = Red; else if (maxLoss > 0) c = WhiteMode?DarkGreen:LawnGreen; else c = WhiteMode?Black:White;
double maxLossp = 0; if (AccountBalance() > 0) maxLossp = MathDiv(maxLoss, AccountBalance() * 100);
text = StringConcatenate("Max loss: ", MTS(maxLoss), " (", DTS(allSLPips, 1), " pips) (", DTS(maxLossp, 2), "%)");
DrawText(0, row, colWidth1, text, c, FontSize);
row++;
DrawText(0, row, 0, "------------------------------------------------------------------", Gray, FontSize);
row++;
//Order counts
c = WhiteMode?DimGray:Gainsboro;
text = StringConcatenate("Long: ", buyCount);
DrawText(0, row, 0, text, c, FontSize);
text = StringConcatenate("Short: ", sellCount);
DrawText(0, row + 1, 0, text, c, FontSize);
DrawText(0, row + 2, 0, "------------------------------------------------------------------", Gray, FontSize);
text = StringConcatenate("Total: ", buyCount + sellCount);
DrawText(0, row + 3, 0, text, c, FontSize);
// Order lots
text = StringConcatenate("LOT: ", DTS(buyLot, 2));
DrawText(0, row, 65, text, c, FontSize);
text = StringConcatenate("LOT: ", DTS(sellLot, 2));
DrawText(0, row + 1, 65, text, c, FontSize);
text = StringConcatenate("LOT: ", DTS(buyLot + sellLot, 2));
DrawText(0, row + 3, 65, text, c, FontSize);
// Order profits
if (buyProfit < 0) c = Crimson; else if (buyProfit == 0.0) c = WhiteMode?DimGray:Gainsboro; else c = WhiteMode?DarkGreen:LawnGreen;
text = StringConcatenate("Profit: ", MTS(buyProfit), " (", DTS(buyPip, 1), " pips)");
DrawText(0, row, colWidth1, text, c, FontSize);
if (sellProfit < 0) c = Crimson; else if (sellProfit == 0.0) c = WhiteMode?DimGray:Gainsboro; else c = WhiteMode?DarkGreen:LawnGreen;
text = StringConcatenate("Profit: ", MTS(sellProfit), " (", DTS(sellPip, 1), " pips)");
DrawText(0, row + 1, colWidth1, text, c, FontSize);
if (buyProfit + sellProfit < 0) c = Crimson; else if (buyProfit + sellProfit == 0.0) c = WhiteMode?DimGray:Gainsboro; else c = WhiteMode?DarkGreen:LawnGreen;
text = StringConcatenate("Profit: ", MTS(buyProfit + sellProfit), " (", DTS(buyPip + sellPip, 1), " pips)");
DrawText(0, row + 3, colWidth1, text, c, FontSize);
}
//+------------------------------------------------------------------+
void DrawProfitHistory() {
//+------------------------------------------------------------------+
if (LastDrawProfitInfo > TimeCurrent() - 10) return;
LastDrawProfitInfo = TimeCurrent();
datetime day, today, now, prevDay;
int xOffset = 150;
if (!ShowRiskInfo) xOffset = 5;
DrawText(1, 0, xOffset + 260, "DATE", Gray, FontSize);
DrawText(1, 0, xOffset + 210, "PIPS", Gray, FontSize);
DrawText(1, 0, xOffset + 130, "PROFIT", Gray, FontSize);
DrawText(1, 0, xOffset + 60, "GAIN %", Gray, FontSize);
DrawText(1, 0, xOffset , "LOT", Gray, FontSize);
DrawText(1, 1, xOffset , "====================================", Gray, FontSize);
now = TimeCurrent();
today = StrToTime(TimeToStr(now, TIME_DATE));
DrawDayHistoryLine(xOffset, today, now, 2, "Today");
day = today; prevDay = GetPreviousDay(day - daySeconds);
DrawDayHistoryLine(xOffset, prevDay, day, 3, "Yesterday");
day = prevDay; prevDay = GetPreviousDay(day - daySeconds);
DrawDayHistoryLine(xOffset, prevDay, day, 4);
day = prevDay; prevDay = GetPreviousDay(day - daySeconds);
DrawDayHistoryLine(xOffset, prevDay, day, 5);
day = prevDay; prevDay = GetPreviousDay(day - daySeconds);
DrawDayHistoryLine(xOffset, prevDay, day, 6);
day = DateOfMonday();
DrawDayHistoryLine(xOffset, day, now, 7, "Week");
day = StrToTime(Year()+"."+Month()+".01");
DrawDayHistoryLine(xOffset, day, now, 8, "Month");
day = StrToTime(Year()+".01.01");
DrawDayHistoryLine(xOffset, day, now, 9, "Year");
DrawText(1, 10, xOffset, "-------------------------------------------------------------------", Gray, FontSize);
// Daily & Monthly profit
if (AccountBalance() != 0.0)
{
double pips, profit, lots = 0;
datetime firstOrderTime = GetHistoryInfoFromDate(day, now, pips, profit, lots);
if (now - firstOrderTime != 0)
{
int oneDay = 86400; //int oneMonth = oneDay * 30.4;
double daily = MathDiv(MathDiv(profit, MathDiv(now - firstOrderTime, oneDay)), (AccountBalance() - profit)) * 100.0;
double monthly = daily * 30.4;
DrawText(1, 11, xOffset, StringConcatenate("Monthly: ", DTS(monthly, 2), "%"), ColorOnSign(monthly), FontSize);
DrawText(1, 11, xOffset + 150, StringConcatenate("Daily: ", DTS(daily, 2), "%"), ColorOnSign(daily), FontSize);
}
}
DrawText(1, 12, xOffset, "====================================", Gray, FontSize);
}
//+------------------------------------------------------------------+
double MathDiv(double a, double b) {
//+------------------------------------------------------------------+
if (b != 0.0)
return(a/b);
return(0.0);
}
//+------------------------------------------------------------------+
void DrawDayHistoryLine(int xOffset, datetime prevDay, datetime day, int row, string header = "") {
//+------------------------------------------------------------------+
if (header == "") header = TimeToStr(prevDay, TIME_DATE);
double pips, profit, percent, lots = 0.0;
string text;
GetHistoryInfoFromDate(prevDay, day, pips, profit, lots);
double profitp = 0;
if (AccountBalance() > 0) profitp = MathDiv(profit, (AccountBalance() - profit)) * 100.0;
text = StringConcatenate(header, ": ");
DrawText(1, row, xOffset + 260, text, WhiteMode?DimGray:Gray, FontSize);
text = DTS(pips, 1);
DrawText(1, row, xOffset + 210, text, ColorOnSign(pips), FontSize);
text = MTS(profit);
DrawText(1, row, xOffset + 120, text, ColorOnSign(profit), FontSize);
text = StringConcatenate(DTS(profitp, 2), "%");
DrawText(1, row, xOffset + 60, text, ColorOnSign(profitp), FontSize);
text = DTS(lots, 2);
DrawText(1, row, xOffset, text, ColorOnSign(profit), FontSize);
}
//+------------------------------------------------------------------+
void DrawTodayRange() {
//+------------------------------------------------------------------+
string text;
SetPipMultiplier(Symbol());
double todayPips = point2pip(iHigh(NULL, PERIOD_D1, 0) - iLow(NULL, PERIOD_D1, 0));
double yesterdayPips = point2pip(iHigh(NULL, PERIOD_D1, 1) - iLow(NULL, PERIOD_D1, 1));
double thisWeekPips = point2pip(iHigh(NULL, PERIOD_W1, 0) - iLow(NULL, PERIOD_W1, 0));
double lastWeekPips = point2pip(iHigh(NULL, PERIOD_W1, 1) - iLow(NULL, PERIOD_W1, 1));
double thisMonthPips = point2pip(iHigh(NULL, PERIOD_MN1, 0) - iLow(NULL, PERIOD_MN1, 0));
double lastMonthPips = point2pip(iHigh(NULL, PERIOD_MN1, 1) - iLow(NULL, PERIOD_MN1, 1));
int colWidth2 = 500;
int colWidth3 = 620;
int row = 1;
color c = C'141,176,241';
DrawText(0, row, colWidth2, "Today range:", c, FontSize); DrawText(0, row, colWidth3, StringConcatenate(DTS(todayPips, 1), " pips"), c, FontSize);
DrawText(0, row + 1, colWidth2, "Yesterday range:", c, FontSize); DrawText(0, row + 1, colWidth3, StringConcatenate(DTS(yesterdayPips, 1), " pips"), c, FontSize);
row += 3;
c = C'103,150,237';
DrawText(0, row, colWidth2, "This week range:", c, FontSize); DrawText(0, row, colWidth3, StringConcatenate(DTS(thisWeekPips, 1), " pips"), c, FontSize);
DrawText(0, row + 1, colWidth2, "Last week range:", c, FontSize); DrawText(0, row + 1, colWidth3, StringConcatenate(DTS(lastWeekPips, 1), " pips"), c, FontSize);
row += 3;
c = C'65,123,233';
DrawText(0, row, colWidth2, "This month range:", c, FontSize); DrawText(0, row, colWidth3, StringConcatenate(DTS(thisMonthPips, 1), " pips"), c, FontSize);
DrawText(0, row + 1, colWidth2, "Last month range:", c, FontSize); DrawText(0, row + 1, colWidth3, StringConcatenate(DTS(lastMonthPips, 1), " pips"), c, FontSize);
row += 3;
datetime nextCandleTime = (Period() * 60) - (TimeCurrent() - iTime(NULL, 0, 0));
c = WhiteMode?Orange:Bisque;
DrawText(0, row, colWidth2, "Next candle:", c, FontSize); DrawText(0, row, colWidth3, TimeToStr(nextCandleTime, TIME_SECONDS), c, FontSize);
}
//+------------------------------------------------------------------+
void DrawCopyright() {
//+------------------------------------------------------------------+
string text = StringConcatenate(IndiName, " - Created by Ice FX - www.icefx.eu");
DrawText(3, 0, 0, text, DimGray, 7);
}
//+------------------------------------------------------------------+
datetime GetHistoryInfoFromDate(datetime prevDay, datetime day, double &pips, double &profit, double &lots) {
//+------------------------------------------------------------------+
datetime res = day;
int i, k = OrdersHistoryTotal();
pips = 0;
profit = 0;
lots = 0;
for (i = 0; i < k; i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
if ( IsValidOrder() ) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
if (day >= OrderCloseTime() && OrderCloseTime() >= prevDay && OrderCloseTime() > startDateFilter) {
profit += OrderProfit() + OrderCommission() + OrderSwap();
if (OrderType() == OP_BUY) {
pips += point2pip(OrderClosePrice() - OrderOpenPrice(), OrderSymbol());
}
if (OrderType() == OP_SELL) {
pips += point2pip(OrderOpenPrice() - OrderClosePrice(), OrderSymbol());
}
lots += OrderLots();
if (OrderCloseTime() < res) res = OrderCloseTime();
}
}
}
}
}
return(res);
}
//+------------------------------------------------------------------+
datetime GetPreviousDay(datetime curDay) {
//+------------------------------------------------------------------+
datetime prevDay = curDay;
while (TimeDayOfWeek(prevDay) < 1 || TimeDayOfWeek(prevDay) > 5) prevDay -= daySeconds;
return(prevDay);
}
//+------------------------------------------------------------------+
datetime DateOfMonday(int no = 0) {
//+------------------------------------------------------------------+
datetime dt = StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));
while (TimeDayOfWeek(dt) != 1) dt -= daySeconds;
dt += no * 7 * daySeconds;
return(dt);
}
color ColorOnSign(double value) {
color lcColor = WhiteMode?DimGray:Gray;
if (value > 0) lcColor = WhiteMode?DarkGreen:Green;
if (value < 0) lcColor = FireBrick;
return(lcColor);
}
//+------------------------------------------------------------------+
double MM(double Risk) {
//+------------------------------------------------------------------+
double SL = RiskStopLoss;
double NewLOT = 0;
string Symb = Symbol(); // Symb default value
double One_Lot = MarketInfo(Symb,MODE_MARGINREQUIRED); // margin for 1 LOT
double Min_Lot = MarketInfo(Symb,MODE_MINLOT); // Minimum LOT
double Max_Lot = MarketInfo(Symb,MODE_MAXLOT); // Maximum LOT
double Step = MarketInfo(Symb,MODE_LOTSTEP); // Lot step
double Free = AccountFreeMargin(); // Free margin
//-------------------------------------------------------------------------------
if (SL > 0) // If set StopLoss
{
double RiskAmount = AccountEquity() * (Risk / 100); // Calc risk in money
double tickValue = MarketInfo(Symb, MODE_TICKVALUE) * pip_multiplier; // Get how many pips 1 unit price
if (tickValue * SL != 0) NewLOT = RiskAmount / (tickValue * SL); // Divide Risk price with SL price
if (Step > 0) NewLOT = MathFloor(NewLOT / Step) * Step; //Round // Round LOT to step
}
//-------------------------------------------------------------------------------
else // Dynamic LOT calculation
{
if (Risk > 100) // If greater then 100
Risk = 100; // then 100%
if (Risk == 0) // If 0
NewLOT = Min_Lot; // then minimal LOT
else
if (Step > 0 && One_Lot > 0)
NewLOT = MathFloor(Free * Risk / 100 / One_Lot / Step) * Step; // Calc by Risk and round to step
}
//-------------------------------------------------------------------------------
if (NewLOT < Min_Lot) // If smaller than minimum
NewLOT = Min_Lot; // set to minimum LOT
if (NewLOT > Max_Lot) // If greater than maximum
NewLOT = Max_Lot; // set to maximum LOT
//-------------------------------------------------------------------------------
double margin = NewLOT * One_Lot; // Calc the required margin for LOT
if (margin > AccountFreeMargin()) // If greater than the free
{ // Message, alert, ...etczenet, alert....stb.
//string msg = "You have not enough money! Free margin: " + DTS(AccountFreeMargin(), 2) + ", Require: " + DTS(margin, 2);
//Log.Warning(msg);
//Print(msg);
//Alert(msg);
return(0); // Return with 0. Skip the order open
}
return(NewLOT);
}
//+------------------------------------------------------------------+
void setCurrency() {
//+------------------------------------------------------------------+
string currSign = AccountCurrency();
if (currSign == "USD") {
preCurrSign = "$";
postCurrSign = postCurrSign;
} else if (currSign == "EUR") {
preCurrSign = "";
postCurrSign = postCurrSign;
} else {
preCurrSign = "";
postCurrSign = postCurrSign;
}
}
//+------------------------------------------------------------------+
string MTS(double value, int decimal = 2) {
//+------------------------------------------------------------------+
return(StringConcatenate(preCurrSign, DTS(value, decimal), postCurrSign));
}
//+------------------------------------------------------------------+
string DTS(double value, int decimal = 0) { return(DoubleToStr(value, decimal)); }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
double point2pip(double point, string Symb = "") {
//+------------------------------------------------------------------+
if (Symb == "") Symb = Symbol();
SetPipMultiplier(Symb);
return(MathDiv(MathDiv(point, MarketInfo(Symb, MODE_POINT)), pip_multiplier));
}
//+------------------------------------------------------------------+
double pip2money(double pip, double lot, string Symb) {
//+------------------------------------------------------------------+
if (Symb == "") Symb = Symbol();
SetPipMultiplier(Symb);
double tickSize = MarketInfo(Symb, MODE_TICKSIZE);
if (tickSize != 0)
{
double onePipValue = MarketInfo(Symb, MODE_TICKVALUE) * (MarketInfo(Symb, MODE_POINT) / tickSize);
return((pip * pip_multiplier) * onePipValue * lot);
} else return(0);
}
//+------------------------------------------------------------------+
double SetPipMultiplier(string Symb, bool simple = false) {
//+------------------------------------------------------------------+
pip_multiplier = 1;
int digit = MarketInfo(Symb, MODE_DIGITS);
if (simple)
{
if (digit % 4 != 0) pip_multiplier = 10;
} else {
if (digit == 5 ||
(digit == 3 && StringFind(Symb, "JPY") > -1) || // If 3 digits and currency is JPY
(digit == 2 && StringFind(Symb, "XAU") > -1) || // If 2 digits and currency is gold
(digit == 2 && StringFind(Symb, "GOLD") > -1) || // If 2 digits and currency is gold
(digit == 3 && StringFind(Symb, "XAG") > -1) || // If 3 digits and currency is silver
(digit == 3 && StringFind(Symb, "SILVER") > -1) || // If 3 digits and currency is silver
(digit == 1)) // If 1 digit (CFDs)
pip_multiplier = 10;
else if (digit == 6 ||
(digit == 4 && StringFind(Symb, "JPY") > -1) || // If 4 digits and currency is JPY
(digit == 3 && StringFind(Symb, "XAU") > -1) || // If 3 digits and currency is gold
(digit == 3 && StringFind(Symb, "GOLD") > -1) || // If 3 digits and currency is gold
(digit == 4 && StringFind(Symb, "XAG") > -1) || // If 4 digits and currency is silver
(digit == 4 && StringFind(Symb, "SILVER") > -1) || // If 4 digits and currency is silver
(digit == 2)) // If 2 digit (CFDs)
pip_multiplier = 100;
}
//Print("PipMultiplier: ", pip_multiplier, ", Digits: ", Digits);
return(pip_multiplier);
}
//+------------------------------------------------------------------+
void DrawText(int corner, int row, int xOffset, string text, color c, int size = 7) {
//+------------------------------------------------------------------+
string objName = "TradeInfo_" + DTS(corner) + "_" + DTS(xOffset) + "_" + DTS(row);
if (ObjectFind(objName) != 0) {
ObjectCreate(objName, OBJ_LABEL, windowIndex, 0, 0);
ObjectSet(objName, OBJPROP_CORNER, corner);
ObjectSet(objName, OBJPROP_SELECTABLE, 0);
ObjectSet(objName, OBJPROP_HIDDEN, 1);
}
ObjectSetText(objName, text, size, "Verdana", c);
ObjectSet(objName, OBJPROP_XDISTANCE, 6 + xOffset);
ObjectSet(objName, OBJPROP_YDISTANCE, 6 + row * (size + 6));
ObjectSet(objName, OBJPROP_BACK, false);
}
//+------------------------------------------------------------------+
double getGlobalVar(string name, double defaultValue = EMPTY_VALUE) {
//+------------------------------------------------------------------+
if (GlobalVariableCheck(name))
return (GlobalVariableGet(name));
else
return (defaultValue);
}
//+------------------------------------------------------------------+
string setGlobalVar(string name, double value = EMPTY_VALUE) {
//+------------------------------------------------------------------+
if (value == EMPTY_VALUE)
GlobalVariableDel(name);
else
GlobalVariableSet(name, value);
return(name);
}
//+------------------------------------------------------------------+
void DeleteAllObject() {
//+------------------------------------------------------------------+
for(int i = ObjectsTotal() - 1; i >= 0; i--)
if(StringFind(ObjectName(i), "TradeInfo_", 0) >= 0)
ObjectDelete(ObjectName(i));
}