forked from EA31337/EA31337-classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SymbolInfo.mqh
766 lines (697 loc) · 26 KB
/
SymbolInfo.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
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
//+------------------------------------------------------------------+
//| EA31337 - multi-strategy advanced trading robot. |
//| Copyright 2016-2018, 31337 Investments Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+
/*
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Prevents processing this includes file for the second time.
#ifndef SYMBOLINFO_MQH
#define SYMBOLINFO_MQH
// Forward declaration.
class SymbolInfo;
class Terminal;
// Includes.
#include "Terminal.mqh"
#ifdef __MQL4__
// Methods of swap calculation at position transfer.
// @see: https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_swap_mode
enum ENUM_SYMBOL_SWAP_MODE {
// Swaps disabled (no swaps).
SYMBOL_SWAP_MODE_DISABLED = -1,
// Swaps are charged in points.
SYMBOL_SWAP_MODE_POINTS = 0,
// Swaps are charged in money in base currency of the symbol.
SYMBOL_SWAP_MODE_CURRENCY_SYMBOL = 1,
// Swaps are charged as the specified annual interest from the instrument price at calculation of swap (standard bank year is 360 days).
SYMBOL_SWAP_MODE_INTEREST_CURRENT = 2,
// Swaps are charged in money in margin currency of the symbol.
SYMBOL_SWAP_MODE_CURRENCY_MARGIN = 3,
// Swaps are charged in money, in client deposit currency.
SYMBOL_SWAP_MODE_CURRENCY_DEPOSIT,
// Swaps are charged as the specified annual interest from the open price of position (standard bank year is 360 days).
SYMBOL_SWAP_MODE_INTEREST_OPEN,
// Swaps are charged by reopening positions. At the end of a trading day the position is closed. Next day it is reopened by the close price +/- specified number of points (parameters SYMBOL_SWAP_LONG and SYMBOL_SWAP_SHORT).
SYMBOL_SWAP_MODE_REOPEN_CURRENT,
// Swaps are charged by reopening positions. At the end of a trading day the position is closed. Next day it is reopened by the current Bid price +/- specified number of points (parameters SYMBOL_SWAP_LONG and SYMBOL_SWAP_SHORT).
SYMBOL_SWAP_MODE_REOPEN_BID
};
#endif
// Constants.
const ENUM_SYMBOL_INFO_DOUBLE market_dcache[] = {SYMBOL_MARGIN_INITIAL, SYMBOL_MARGIN_LIMIT, SYMBOL_MARGIN_LONG, SYMBOL_MARGIN_MAINTENANCE, SYMBOL_MARGIN_SHORT, SYMBOL_MARGIN_STOP, SYMBOL_MARGIN_STOPLIMIT, SYMBOL_POINT, SYMBOL_SWAP_LONG, SYMBOL_SWAP_SHORT, SYMBOL_TRADE_CONTRACT_SIZE, SYMBOL_TRADE_TICK_SIZE, SYMBOL_TRADE_TICK_VALUE, SYMBOL_TRADE_TICK_VALUE_LOSS, SYMBOL_TRADE_TICK_VALUE_PROFIT, SYMBOL_VOLUME_LIMIT, SYMBOL_VOLUME_MAX, SYMBOL_VOLUME_MIN, SYMBOL_VOLUME_STEP};
const ENUM_SYMBOL_INFO_INTEGER market_icache[] = {SYMBOL_DIGITS, SYMBOL_EXPIRATION_MODE, SYMBOL_FILLING_MODE, SYMBOL_ORDER_MODE, SYMBOL_SWAP_MODE, SYMBOL_SWAP_ROLLOVER3DAYS, SYMBOL_TRADE_CALC_MODE, SYMBOL_TRADE_EXEMODE, SYMBOL_TRADE_MODE };
/**
* Class to provide symbol information.
*/
class SymbolInfo : public Terminal {
protected:
// Variables.
string symbol; // Current symbol pair.
MqlTick last_tick; // Stores the latest prices of the symbol.
MqlTick tick_data[]; // Stores saved ticks.
double pip_size; // Value of pip size.
uint symbol_digits; // Count of digits after decimal point in the symbol price.
//uint pts_per_pip; // Number of points per pip.
double volume_precision;
public:
/**
* Implements class constructor with a parameter.
*/
SymbolInfo(string _symbol = NULL, Log *_log = NULL) :
symbol(_symbol == NULL ? _Symbol : _symbol),
pip_size(GetPipSize()),
symbol_digits(GetDigits()),
Terminal(_log)
{
Select();
last_tick = GetTick();
}
~SymbolInfo() {
}
/**
* Selects current symbol in the Market Watch window.
*
* @docs
* - https://docs.mql4.com/marketinformation/symbolselect
* - https://www.mql5.com/en/docs/MarketInformation/SymbolSelect
*/
bool Select() {
return (bool) SymbolInfoInteger(symbol, SYMBOL_SELECT);
}
/* Getters */
/**
* Get the current symbol pair from the current chart.
*/
static string GetCurrentSymbol() {
return _Symbol;
}
/**
* Get current symbol pair used by the class.
*/
string GetSymbol() {
return symbol;
}
/**
* Updates and gets the latest tick prices.
*
* @docs MQL4 https://docs.mql4.com/constants/structures/mqltick
* @docs MQL5 https://www.mql5.com/en/docs/constants/structures/mqltick
*/
static MqlTick GetTick(string _symbol) {
MqlTick _last_tick;
if (!SymbolInfoTick(_symbol, _last_tick)) {
PrintFormat("Error: %s(): %s", __FUNCTION__, "Cannot return current prices!");
}
return _last_tick;
}
MqlTick GetTick() {
if (!SymbolInfoTick(this.symbol, this.last_tick)) {
Logger().Error("Cannot return current prices!", __FUNCTION__);
}
return this.last_tick;
}
/**
* Gets the last tick prices (without updating).
*/
MqlTick GetLastTick() {
return this.last_tick;
}
/**
* The latest known seller's price (ask price) for the current symbol.
* The RefreshRates() function must be used to update.
*
* @see http://docs.mql4.com/predefined/ask
*/
double Ask() {
return this.GetTick().ask;
// @todo?
// Overriding Ask variable to become a function call.
// #ifdef __MQL5__ #define Ask Market::Ask() #endif // @fixme
}
/**
* Updates and gets the latest ask price (best buy offer).
*/
static double GetAsk(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_ASK);
}
double GetAsk() {
return this.GetAsk(symbol);
}
/**
* Gets the last ask price (without updating).
*/
double GetLastAsk() {
return this.last_tick.ask;
}
/**
* The latest known buyer's price (offer price, bid price) of the current symbol.
* The RefreshRates() function must be used to update.
*
* @see http://docs.mql4.com/predefined/bid
*/
double Bid() {
return this.GetTick().bid;
// @todo?
// Overriding Bid variable to become a function call.
// #ifdef __MQL5__ #define Bid Market::Bid() #endif // @fixme
}
/**
* Updates and gets the latest bid price (best sell offer).
*/
static double GetBid(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_BID);
}
double GetBid() {
return this.GetBid(symbol);
}
/**
* Gets the last bid price (without updating).
*/
double GetLastBid() {
return this.last_tick.bid;
}
/**
* Get the last volume for the current last price.
*
* @see: https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants
*/
static ulong GetVolume(string _symbol) {
return GetTick(_symbol).volume;
}
ulong GetVolume() {
return this.GetTick(this.symbol).volume;
}
/**
* Gets the last volume for the current price (without updating).
*/
ulong GetLastVolume() {
return this.last_tick.volume;
}
/**
* Get summary volume of current session deals.
*
* @see: https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants
*/
static double GetSessionVolume(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_SESSION_VOLUME);
}
double GetSessionVolume() {
return this.GetSessionVolume(this.symbol);
}
/**
* Time of the last quote
*
* @docs
* - https://docs.mql4.com/constants/environment_state/marketinfoconstants
* - https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_info_double
*/
static datetime GetQuoteTime(string _symbol) {
return (datetime) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_TIME);
}
datetime GetQuoteTime() {
return GetQuoteTime(this.symbol);
}
/**
* Get current open price depending on the operation type.
*
* @param:
* op_type int Order operation type of the order.
* @return
* Current open price.
*/
static double GetOpenOffer(string _symbol, ENUM_ORDER_TYPE _cmd) {
// Use the right open price at opening of a market order. For example:
// - When selling, only the latest Bid prices can be used.
// - When buying, only the latest Ask prices can be used.
return _cmd == ORDER_TYPE_BUY ? GetAsk(_symbol) : GetBid(_symbol);
}
double GetOpenOffer(ENUM_ORDER_TYPE _cmd) {
return GetOpenOffer(symbol, _cmd);
}
/**
* Get current close price depending on the operation type.
*
* @param:
* op_type int Order operation type of the order.
* @return
* Current close price.
*/
static double GetCloseOffer(string _symbol, ENUM_ORDER_TYPE _cmd) {
return _cmd == ORDER_TYPE_BUY ? GetBid(_symbol) : GetAsk(_symbol);
}
double GetCloseOffer(ENUM_ORDER_TYPE _cmd) {
return GetCloseOffer(symbol, _cmd);
}
/**
* Get the point size in the quote currency.
*
* The smallest digit of price quote.
* A change of 1 in the least significant digit of the price.
* You may also use Point predefined variable for the current symbol.
*/
double GetPointSize() {
return SymbolInfo::SymbolInfoDouble(symbol, SYMBOL_POINT); // Same as: MarketInfo(symbol, MODE_POINT);
}
static double GetPointSize(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_POINT); // Same as: MarketInfo(symbol, MODE_POINT);
}
/**
* Return a pip size.
*
* In most cases, a pip is equal to 1/100 (.01%) of the quote currency.
*/
static double GetPipSize(string _symbol) {
// @todo: This code may fail at Gold and Silver (https://www.mql5.com/en/forum/135345#515262).
return GetDigits(_symbol) % 2 == 0 ? GetPointSize(_symbol) : GetPointSize(_symbol) * 10;
}
double GetPipSize() {
return GetPipSize(symbol);
}
/**
* Get a tick size in the price value.
*
* It is the smallest movement in the price quoted by the broker,
* which could be several points.
* In currencies it is equivalent to point size, in metals they are not.
*/
static double GetTickSize(string _symbol) {
// Note: In currencies a tick is always a point, but not for other markets.
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_SIZE);
}
double GetTickSize() {
return GetTickSize(symbol);
}
/**
* Get a tick size in points.
*
* It is a minimal price change in points.
* In currencies it is equivalent to point size, in metals they are not.
*/
static double GetTradeTickSize(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_SIZE);
}
double GetTradeTickSize() {
return GetTradeTickSize(symbol);
}
/**
* Get a tick value in the deposit currency.
*
* @return
* Returns the number of base currency units for one pip of movement.
*/
static double GetTickValue(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_VALUE); // Same as: MarketInfo(symbol, MODE_TICKVALUE);
}
double GetTickValue() {
return GetTickValue(symbol);
}
/**
* Get a calculated tick price for a profitable position.
*
* @return
* Returns the number of base currency units for one pip of movement.
*/
static double GetTickValueProfit(string _symbol) {
// Not supported in MQL4.
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_VALUE_PROFIT); // Same as: MarketInfo(symbol, SYMBOL_TRADE_TICK_VALUE_PROFIT);
}
double GetTickValueProfit() {
return GetTickValueProfit(symbol);
}
/**
* Get a calculated tick price for a losing position.
*
* @return
* Returns the number of base currency units for one pip of movement.
*/
static double GetTickValueLoss(string _symbol) {
// Not supported in MQL4.
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_TRADE_TICK_VALUE_LOSS); // Same as: MarketInfo(symbol, SYMBOL_TRADE_TICK_VALUE_LOSS);
}
double GetTickValueLoss() {
return GetTickValueLoss(symbol);
}
/**
* Get count of digits after decimal point for the symbol price.
*
* For the current symbol, it is stored in the predefined variable Digits.
*
*/
static uint GetDigits(string _symbol) {
return (uint) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_DIGITS); // Same as: MarketInfo(symbol, MODE_DIGITS);
}
uint GetDigits() {
return GetDigits(symbol);
}
/**
* Get current spread in points.
*
* @param
* symbol string (optional)
* Currency pair symbol.
*
* @return
* Return symbol trade spread level in points.
*/
static uint GetSpread(string _symbol) {
return (uint) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_SPREAD);
}
uint GetSpread() {
return GetSpread(symbol);
}
/**
* Get real spread based on the ask and bid price (in points).
*/
static uint GetRealSpread(string _symbol) {
return (uint) round((GetAsk(_symbol) - GetBid(_symbol)) * pow(10, GetDigits(_symbol)));
}
uint GetRealSpread() {
return GetRealSpread(symbol);
}
/**
* Minimal indention in points from the current close price to place Stop orders.
*
* This is due that at placing of a pending order, the open price cannot be too close to the market.
* The minimal distance of the pending price from the current market one in points can be obtained
* using the MarketInfo() function with the MODE_STOPLEVEL parameter.
* Related error messages:
* Error 130 (ERR_INVALID_STOPS) happens In case of false open price of a pending order.
* Error 145 (ERR_TRADE_MODIFY_DENIED) happens when modification of order was too close to market.
*
* @param
* symbol string (optional)
* Currency pair symbol.
*
* @return
* Returns the minimal permissible distance value in points for StopLoss/TakeProfit.
* A zero value means either absence of any restrictions on the minimal distance.
*
* @see: https://book.mql4.com/appendix/limits
*/
long GetTradeStopsLevel() {
return SymbolInfo::SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL);
}
static long GetTradeStopsLevel(string _symbol) {
return SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_TRADE_STOPS_LEVEL);
}
/**
* Get a contract lot size in the base currency.
*/
double GetTradeContractSize() {
return SymbolInfo::SymbolInfoDouble(symbol, SYMBOL_TRADE_CONTRACT_SIZE); // Same as: MarketInfo(symbol, MODE_LOTSIZE);
}
static double GetTradeContractSize(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_TRADE_CONTRACT_SIZE); // Same as: MarketInfo(symbol, MODE_LOTSIZE);
}
/**
* Minimum permitted amount of a lot/volume for a deal.
*/
static double GetVolumeMin(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_VOLUME_MIN); // Same as: MarketInfo(symbol, MODE_MINLOT);
}
double GetVolumeMin() {
return GetVolumeMin(symbol);
}
/**
* Maximum permitted amount of a lot/volume for a deal.
*/
static double GetVolumeMax(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_VOLUME_MAX); // Same as: MarketInfo(symbol, MODE_MAXLOT);
}
double GetVolumeMax() {
return GetVolumeMax(symbol);
}
/**
* Get a lot/volume step for a deal.
*
* Minimal volume change step for deal execution
*/
static double GetVolumeStep(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_VOLUME_STEP); // Same as: MarketInfo(symbol, MODE_LOTSTEP);
}
double GetVolumeStep() {
return GetVolumeStep(symbol);
}
/**
* Order freeze level in points.
*
* Freeze level is a value that determines the price band,
* within which the order is considered as 'frozen' (prohibited to change).
*
* If the execution price lies within the range defined by the freeze level,
* the order cannot be modified, cancelled or closed.
* The possibility of deleting a pending order is regulated by the FreezeLevel.
*
* @see: https://book.mql4.com/appendix/limits
*/
static uint GetFreezeLevel(string _symbol) {
return (uint) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_TRADE_FREEZE_LEVEL); // Same as: MarketInfo(symbol, MODE_FREEZELEVEL);
}
uint GetFreezeLevel() {
return GetFreezeLevel(symbol);
}
/**
* Gets flags of allowed order filling modes.
*
* The flags can be combined by the operation of the logical OR (e.g. SYMBOL_FILLING_FOK|SYMBOL_FILLING_IOC).
*
* @docs
* - https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#symbol_filling_mode
* - https://docs.mql4.com/constants/environment_state/marketinfoconstants
*/
static ENUM_ORDER_TYPE_FILLING GetFillingMode(string _symbol) {
// Note: Not supported for MQL4.
return (ENUM_ORDER_TYPE_FILLING) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_FILLING_MODE);
}
ENUM_ORDER_TYPE_FILLING GetFillingMode() {
return GetFillingMode(symbol);
}
/**
* Buy order swap value
*
* @docs
* - https://docs.mql4.com/constants/environment_state/marketinfoconstants
* - https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants
*/
static double GetSwapLong(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_SWAP_LONG);
}
double GetSwapLong() {
return GetSwapLong(symbol);
}
/**
* Sell order swap value
*
* @docs
* - https://docs.mql4.com/constants/environment_state/marketinfoconstants
* - https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants
*/
static double GetSwapShort(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_SWAP_SHORT);
}
double GetSwapShort() {
return GetSwapShort(symbol);
}
/**
* Swap calculation model.
*
* @docs
* - https://docs.mql4.com/constants/environment_state/marketinfoconstants
* - https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants
*/
static ENUM_SYMBOL_SWAP_MODE GetSwapMode(string _symbol) {
return (ENUM_SYMBOL_SWAP_MODE) SymbolInfo::SymbolInfoInteger(_symbol, SYMBOL_SWAP_MODE);
}
ENUM_SYMBOL_SWAP_MODE GetSwapMode() {
return GetSwapMode(symbol);
}
/**
* Initial margin (a security deposit) requirements for 1 lot.
*
* Initial margin means the amount in the margin currency required for opening a position with the volume of one lot.
* It is used for checking a client's assets when he or she enters the market.
*
* @docs
* - https://docs.mql4.com/constants/environment_state/marketinfoconstants
* - https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_info_double
*/
static double GetMarginInit(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_MARGIN_INITIAL); // Same as: MarketInfo(symbol, MODE_MARGININIT);
}
double GetMarginInit() {
return GetMarginInit(symbol);
}
/**
* Margin to maintain open orders calculated for 1 lot
*
* If it is set, it sets the margin amount in the margin currency of the symbol, charged from one lot.
* It is used for checking a client's assets when his/her account state changes.
* If the maintenance margin is equal to 0, the initial margin is used.
*
* @docs
* - https://docs.mql4.com/constants/environment_state/marketinfoconstants
* - https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants#enum_symbol_info_double
*/
static double GetMarginMaintenance(string _symbol) {
return SymbolInfo::SymbolInfoDouble(_symbol, SYMBOL_MARGIN_MAINTENANCE); // Same as: MarketInfo(symbol, SYMBOL_MARGIN_MAINTENANCE);
}
double GetMarginMaintenance() {
return GetMarginMaintenance(symbol);
}
/* Tick storage */
/**
* Appends a new tick to an array.
*/
bool SaveTick(MqlTick &_tick) {
static int _index = 0;
if (_index++ >= ArraySize(this.tick_data) - 1) {
if (ArrayResize(this.tick_data, _index + 100, 1000) < 0) {
Logger().Error(StringFormat("Cannot resize array (size: %d)!", _index), __FUNCTION__);
return false;
}
}
this.tick_data[_index] = this.GetTick();
return true;
}
/**
* Empties the tick array.
*/
bool ResetTicks() {
return ArrayResize(this.tick_data, 0, 100) != -1;
}
/* Setters */
/**
* Overrides the last tick.
*/
void SetTick(MqlTick &_tick) {
this.last_tick = _tick;
}
/**
* Returns the value of a corresponding property of the symbol.
*
* @param string name
* Symbol name.
* @param ENUM_SYMBOL_INFO_DOUBLE prop_id
* Identifier of a property.
*
* @return double
* Returns the value of the property.
* In case of error, information can be obtained using GetLastError() function.
*
* @docs
* - https://docs.mql4.com/marketinformation/symbolinfodouble
* - https://www.mql5.com/en/docs/marketinformation/symbolinfodouble
*
*/
static double SymbolInfoDouble(string name, ENUM_SYMBOL_INFO_DOUBLE prop_id) {
#ifdef __MQLBUILD__
return ::SymbolInfoDouble(name, prop_id);
#else
printf("@fixme: %s\n", "Symbol::SymbolInfoDouble()");
return 0;
#endif
}
/**
* Returns the value of a corresponding property of the symbol.
*
* @param string name
* Symbol name.
* @param ENUM_SYMBOL_INFO_INTEGER prop_id
* Identifier of a property.
*
* @return long
* Returns the value of the property.
* In case of error, information can be obtained using GetLastError() function.
*
* @docs
* - https://docs.mql4.com/marketinformation/symbolinfointeger
* - https://www.mql5.com/en/docs/marketinformation/symbolinfointeger
*
*/
static long SymbolInfoInteger(string name, ENUM_SYMBOL_INFO_INTEGER prop_id) {
#ifdef __MQLBUILD__
return ::SymbolInfoInteger(name, prop_id);
#else
printf("@fixme: %s\n", "SymbolInfo::SymbolInfoInteger()");
return 0;
#endif
}
/**
* Returns the value of a corresponding property of the symbol.
*
* @param string name
* Symbol name.
* @param ENUM_SYMBOL_INFO_STRING prop_id
* Identifier of a property.
*
* @return string
* Returns the value of the property.
* In case of error, information can be obtained using GetLastError() function.
*
* @docs
* - https://docs.mql4.com/marketinformation/symbolinfostring
* - https://www.mql5.com/en/docs/marketinformation/symbolinfostring
*
*/
static string SymbolInfoString(string name, ENUM_SYMBOL_INFO_STRING prop_id) {
#ifdef __MQLBUILD__
return ::SymbolInfoString(name, prop_id);
#else
printf("@fixme: %s\n", "SymbolInfo::SymbolInfoString()");
return 0;
#endif
}
/* Printer methods */
/**
* Returns symbol information in string format.
*/
string ToString() {
return StringFormat(
"Symbol: %s, Last Ask/Bid: %g/%g, Last Price/Session Volume: %d/%g, Point size: %g, Pip size: %g, " +
"Tick size: %g (%g pts), Tick value: %g (%g/%g), " +
"Digits: %d, Spread: %d pts, Trade stops level: %d, " +
"Trade contract size: %g, Min lot: %g, Max lot: %g, Lot step: %g, " +
"Freeze level: %d, Swap (long/short/mode): %g/%g/%d, Margin initial (maintenance): %g (%g)",
GetSymbol(), GetLastAsk(), GetLastBid(), GetLastVolume(), GetSessionVolume(), GetPointSize(), GetPipSize(),
GetTickSize(), GetTradeTickSize(), GetTickValue(), GetTickValueProfit(), GetTickValueLoss(),
GetDigits(), GetSpread(), GetTradeStopsLevel(),
GetTradeContractSize(), GetVolumeMin(), GetVolumeMax(), GetVolumeStep(),
GetFreezeLevel(), GetSwapLong(), GetSwapShort(), GetSwapMode(), GetMarginInit(), GetMarginMaintenance()
);
}
/**
* Returns symbol information in CSV format.
*/
string ToCSV(bool _header = false) {
return
!_header ? StringFormat(
"%s,%g,%g,%d,%g,%g,%g," +
"%g,%g,%g,%g,%g," +
"%d,%d,%d," +
"%g,%g,%g,%g," +
"%d,%g,%g,%d,%g,%g",
GetSymbol(), GetLastAsk(), GetLastBid(), GetLastVolume(), GetSessionVolume(), GetPointSize(), GetPipSize(),
GetTickSize(), GetTradeTickSize(), GetTickValue(), GetTickValueProfit(), GetTickValueLoss(),
GetDigits(), GetSpread(), GetTradeStopsLevel(),
GetTradeContractSize(), GetVolumeMin(), GetVolumeMax(), GetVolumeStep(),
GetFreezeLevel(), GetSwapLong(), GetSwapShort(), GetSwapMode(), GetMarginInit(), GetMarginMaintenance()
)
:
"Symbol,Last Ask,Last Bid,Last Volume,Session Volume,Point Size,Pip Size," +
"Tick Size,Tick Size (pts),Tick Value,Tick Value Profit,Tick Value Loss," +
"Digits,Spread (pts),Trade Stops," +
"Trade Contract Size,Min Lot,Max Lot,Lot Step," +
"Freeze level, Swap Long, Swap Short, Swap Mode, Margin Init";
}
};
#endif // SYMBOLINFO_MQH