forked from vdemydiuk/mtapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMtApi5.mq5
executable file
·5773 lines (5237 loc) · 166 KB
/
MtApi5.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
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
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#property copyright "Vyacheslav Demidyuk"
#property link ""
#property version "1.4"
#property description "MtApi (MT5) connection expert"
#include <json.mqh>
#include <Trade\SymbolInfo.mqh>
#include <trade/trade.mqh>
#import "MT5Connector.dll"
bool initExpert(int expertHandle, int port, string symbol, double bid, double ask, int isTestMode, string& err);
bool deinitExpert(int expertHandle, string& err);
bool updateQuote(int expertHandle, string symbol, double bid, double ask, string& err);
bool sendIntResponse(int expertHandle, int response, string& err);
bool sendBooleanResponse(int expertHandle, int response, string& err);
bool sendDoubleResponse(int expertHandle, double response, string& err);
bool sendStringResponse(int expertHandle, string response, string& err);
bool sendVoidResponse(int expertHandle, string& err);
bool sendDoubleArrayResponse(int expertHandle, double& values[], int size, string& err);
bool sendIntArrayResponse(int expertHandle, int& values[], int size, string& err);
bool sendLongResponse(int expertHandle, long response, string& err);
bool sendULongResponse(int expertHandle, ulong response, string& err);
bool sendLongArrayResponse(int expertHandle, long& values[], int size, string& err);
bool sendMqlRatesArrayResponse(int expertHandle, MqlRates& values[], int size, string& err);
bool sendMqlTickResponse(int expertHandle, MqlTick& response, string& err);
bool sendMqlBookInfoArrayResponse(int expertHandle, MqlBookInfo& values[], int size, string& err);
bool sendErrorResponse(int expertHandle, int code, string message, string& err);
bool getCommandType(int expertHandle, int& res, string& err);
bool getIntValue(int expertHandle, int paramIndex, int& res, string& err);
bool getUIntValue(int expertHandle, int paramIndex, uint& res, string& err);
bool getULongValue(int expertHandle, int paramIndex, ulong& res, string& err);
bool getLongValue(int expertHandle, int paramIndex, long& res, string& err);
bool getDoubleValue(int expertHandle, int paramIndex, double& res, string& err);
bool getStringValue(int expertHandle, int paramIndex, string& res, string& err);
bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err);
#import
//#define __DEBUG_LOG__
input int Port = 8228;
int ExpertHandle;
//string message;
string _error;
string _response_error;
bool isCrashed = false;
bool IsRemoteReadyForTesting = false;
string PARAM_SEPARATOR = ";";
int OnInit()
{
int result = init();
return (result);
}
double OnTester()
{
Print("OnTester");
return 0;
}
void OnDeinit(const int reason)
{
deinit();
}
void OnTick()
{
start();
}
int preinit()
{
StringInit(_response_error,1000,0);
return (0);
}
bool IsDemo()
{
if(AccountInfoInteger(ACCOUNT_TRADE_MODE)==ACCOUNT_TRADE_MODE_DEMO)
return(true);
else
return(false);
}
bool IsTesting()
{
bool isTesting = MQLInfoInteger(MQL_TESTER);
#ifdef __DEBUG_LOG__
PrintFormat("IsTesting: %s", isTesting ? "true" : "false");
#endif
return isTesting;
}
int init()
{
preinit();
if (TerminalInfoInteger(TERMINAL_DLLS_ALLOWED) == false)
{
MessageBox("Dlls not allowed.", "MtApi", 0);
isCrashed = true;
return (1);
}
if (MQL5InfoInteger(MQL5_DLLS_ALLOWED) == false)
{
MessageBox("Libraries not allowed.", "MtApi", 0);
isCrashed = true;
return (1);
}
if (MQL5InfoInteger(MQL5_TRADE_ALLOWED) == false)
{
MessageBox("Trade not allowed.", "MtApi", 0);
isCrashed = true;
return (1);
}
long chartID = ChartID();
ExpertHandle = (int) ChartGetInteger(chartID, CHART_WINDOW_HANDLE);
MqlTick last_tick;
SymbolInfoTick(Symbol(),last_tick);
double Bid = last_tick.bid;
double Ask = last_tick.ask;
if (!initExpert(ExpertHandle, Port, Symbol(), Bid, Ask, IsTesting(), _error))
{
MessageBox(_error, "MtApi", 0);
isCrashed = true;
return(1);
}
if (executeCommand() == 1)
{
isCrashed = true;
return (1);
}
#ifdef __DEBUG_LOG__
PrintFormat("Expert Handle = %d", ExpertHandle);
#endif
//--- Backtesting mode
if (IsTesting())
{
Print("Waiting on remote client...");
//wait for command (BacktestingReady) from remote side to be ready for work
while(!IsRemoteReadyForTesting)
{
executeCommand();
//This section uses a while loop to simulate Sleep() during Backtest.
unsigned int viSleepUntilTick = GetTickCount() + 100; //100 milliseconds
while(GetTickCount() < viSleepUntilTick)
{
//Do absolutely nothing. Just loop until the desired tick is reached.
}
}
}
//---
return (0);
}
int deinit()
{
if (isCrashed == 0)
{
if (!deinitExpert(ExpertHandle, _error))
{
MessageBox(_error, "MtApi", 0);
isCrashed = true;
return (1);
}
Print("Expert was deinitialized.");
}
return (0);
}
int start()
{
MqlTick last_tick;
SymbolInfoTick(Symbol(),last_tick);
double Bid = last_tick.bid;
double Ask = last_tick.ask;
if (!updateQuote(ExpertHandle, Symbol(), Bid, Ask, _error))
{
Print("updateQuote: [ERROR] ", _error);
}
return (0);
}
void OnTimer()
{
while(true)
{
int executedCommand = executeCommand();
if (executedCommand == 0)
{
return;
}
}
}
int executeCommand()
{
int commandType = 0;
if (!getCommandType(ExpertHandle, commandType, _error))
{
Print("[ERROR] ExecuteCommand: Failed to get command type! ", _error);
return (0);
}
#ifdef __DEBUG_LOG__
if (commandType > 0)
{
Print("executeCommand: commnad type = ", commandType);
}
#endif
switch (commandType)
{
case 0:
//NoCommand
break;
case 155: //Request
Execute_Request();
break;
case 1: // OrderSend
Execute_OrderSend();
break;
case 63: //OrderCloseAll
Execute_OrderCloseAll();
break;
case 64: //PositionClose
Execute_PositionClose();
break;
case 2: // OrderCalcMargin
Execute_OrderCalcMargin();
break;
case 3: //OrderCalcProfit
Execute_OrderCalcProfit();
break;
case 4: //OrderCheck
Execute_OrderCheck();
break;
case 6: //PositionsTotal
Execute_PositionsTotal();
break;
case 7: //PositionGetSymbol
Execute_PositionGetSymbol();
break;
case 8: //PositionSelect
Execute_PositionSelect();
break;
case 9: //PositionGetDouble
Execute_PositionGetDouble();
break;
case 10: //PositionGetInteger
Execute_PositionGetInteger();
break;
case 11: //PositionGetString
Execute_PositionGetString();
break;
case 12: //OrdersTotal
Execute_OrdersTotal();
break;
case 13: //OrderGetTicket
Execute_OrderGetTicket();
break;
case 14: //OrderSelect
Execute_OrderSelect();
break;
case 15: //OrderGetDouble
Execute_OrderGetDouble();
break;
case 16: //OrderGetInteger
Execute_OrderGetInteger();
break;
case 17: //OrderGetString
Execute_OrderGetString();
break;
case 18: //HistorySelect
Execute_HistorySelect();
break;
case 19: //HistorySelectByPosition
Execute_HistorySelectByPosition();
break;
case 20: //HistoryOrderSelect
Execute_HistoryOrderSelect();
break;
case 21: //HistoryOrdersTotal
Execute_HistoryOrdersTotal();
break;
case 22: //HistoryOrderGetTicket
Execute_HistoryOrderGetTicket();
break;
case 23: //HistoryOrderGetDouble
Execute_HistoryOrderGetDouble();
break;
case 24: //HistoryOrderGetInteger
Execute_HistoryOrderGetInteger();
break;
case 25: //HistoryOrderGetString
Execute_HistoryOrderGetString();
break;
case 26: //HistoryDealSelect
Execute_HistoryDealSelect();
break;
case 27: //HistoryDealsTotal
Execute_HistoryDealsTotal();
break;
case 28: //HistoryDealGetTicket
Execute_HistoryDealGetTicket();
break;
case 29: //HistoryDealGetDouble
Execute_HistoryDealGetDouble();
break;
case 30: //HistoryDealGetInteger
Execute_HistoryDealGetInteger();
break;
case 31: //HistoryDealGetString
Execute_HistoryDealGetString();
break;
case 32: //AccountInfoDouble
Execute_AccountInfoDouble();
break;
case 33: //AccountInfoInteger
Execute_AccountInfoInteger();
break;
case 34: //AccountInfoString
Execute_AccountInfoString();
break;
case 35: //SeriesInfoInteger
Execute_SeriesInfoInteger();
break;
case 36: //Bars
Execute_Bars();
break;
case 1036: //Bars2
Execute_Bars2();
break;
case 37: //BarsCalculated
Execute_BarsCalculated();
break;
case 40: //CopyBuffer
Execute_CopyBuffer();
break;
case 1040: //CopyBuffer1
Execute_CopyBuffer1();
break;
case 1140: //CopyBuffer2
Execute_CopyBuffer2();
break;
case 41: //CopyRates
Execute_CopyRates();
break;
case 1041: //CopyRates1
Execute_CopyRates1();
break;
case 1141: //CopyRates2
Execute_CopyRates2();
break;
case 42: //CopyTime
Execute_CopyTime();
break;
case 1042: //CopyTime1
Execute_CopyTime1();
break;
case 1142: //CopyTime2
Execute_CopyTime2();
break;
case 43: //CopyOpen
Execute_CopyOpen();
break;
case 1043: //CopyOpen1
Execute_CopyOpen1();
break;
case 1143: //CopyOpen2
Execute_CopyOpen2();
break;
case 44: //CopyHigh
Execute_CopyHigh();
break;
case 1044: //CopyHigh1
Execute_CopyHigh1();
break;
case 1144: //CopyHigh2
Execute_CopyHigh2();
break;
case 45: //CopyLow
Execute_CopyLow();
break;
case 1045: //CopyLow1
Execute_CopyLow1();
break;
case 1145: //CopyLow2
Execute_CopyLow2();
break;
case 46: //CopyClose
Execute_CopyClose();
break;
case 1046: //CopyClose1
Execute_CopyClose1();
break;
case 1146: //CopyClose2
Execute_CopyClose2();
break;
case 47: //CopyTickVolume
Execute_CopyTickVolume();
break;
case 1047: //CopyTickVolume1
Execute_CopyTickVolume1();
break;
case 1147: //CopyTickVolume2
Execute_CopyTickVolume2();
break;
case 48: //CopyRealVolume
Execute_CopyRealVolume();
break;
case 1048: //CopyRealVolume1
Execute_CopyRealVolume1();
break;
case 1148: //CopyRealVolume2
Execute_CopyRealVolume2();
break;
case 49: //CopySpread
Execute_CopySpread();
break;
case 1049: //CopySpread1
Execute_CopySpread1();
break;
case 1149: //CopySpread2
Execute_CopySpread2();
break;
case 50: //SymbolsTotal
Execute_SymbolsTotal();
break;
case 51: //SymbolName
Execute_SymbolName();
break;
case 52: //SymbolSelect
Execute_SymbolSelect();
break;
case 53: //SymbolIsSynchronized
Execute_SymbolIsSynchronized();
break;
case 54: //SymbolInfoDouble
Execute_SymbolInfoDouble();
break;
case 55: //SymbolInfoInteger
Execute_SymbolInfoInteger();
break;
case 56: //SymbolInfoString
Execute_SymbolInfoString();
break;
case 57: //SymbolInfoTick
Execute_SymbolInfoTick();
break;
case 58: //SymbolInfoSessionQuote
Execute_SymbolInfoSessionQuote();
break;
case 59: //SymbolInfoSessionTrade
Execute_SymbolInfoSessionTrade();
break;
case 60: //MarketBookAdd
Execute_MarketBookAdd();
break;
case 61: //MarketBookRelease
Execute_MarketBookRelease();
break;
case 62: //MarketBookGet
Execute_MarketBookGet();
break;
case 65: //PositionOpen
Execute_PositionOpen(false);
break;
case 1065: //PositionOpenWithResult
Execute_PositionOpen(true);
break;
case 66: //BacktestingReady
Execute_BacktestingReady();
break;
case 67: //IsTesting
Execute_IsTesting();
break;
case 68: //Print
Execute_Print();
break;
case 69: //PositionSelectByTicket
Execute_PositionSelectByTicket();
break;
case 70: //ObjectCreate
Execute_ObjectCreate();
break;
case 71: //ObjectName
Execute_ObjectName();
break;
case 72: //ObjectDelete
Execute_ObjectDelete();
break;
case 73: //ObjectsDeleteAll
Execute_ObjectsDeleteAll();
break;
case 74: //ObjectFind
Execute_ObjectFind();
break;
case 75: //ObjectGetTimeByValue
Execute_ObjectGetTimeByValue();
break;
case 76: //ObjectGetValueByTime
Execute_ObjectGetValueByTime();
break;
case 77: //ObjectMove
Execute_ObjectMove();
break;
case 78: //ObjectsTotal
Execute_ObjectsTotal();
break;
case 79: //ObjectGetDouble
Execute_ObjectGetDouble();
break;
case 80: //ObjectGetInteger
Execute_ObjectGetInteger();
break;
case 81: //ObjectGetString
Execute_ObjectGetString();
break;
case 82: //ObjectSetDouble
Execute_ObjectSetDouble();
break;
case 83: //ObjectSetInteger
Execute_ObjectSetInteger();
break;
case 84: //ObjectSetString
Execute_ObjectSetString();
break;
case 88: //iAC
Execute_iAC();
break;
case 89: //iAD
Execute_iAD();
break;
case 90: //iADX
Execute_iADX();
break;
case 91: //iADXWilder
Execute_iADXWilder();
break;
case 92: //iAlligator
Execute_iAlligator();
break;
case 93: //iAMA
Execute_iAMA();
break;
case 94: //iAO
Execute_iAO();
break;
case 95: //iATR
Execute_iATR();
break;
case 96: //iBearsPower
Execute_iBearsPower();
break;
case 97: //iBands
Execute_iBands();
break;
case 98: //iBullsPower
Execute_iBullsPower();
break;
case 99: //iCCI
Execute_iCCI();
break;
case 100: //iChaikin
Execute_iChaikin();
break;
// case 101: //iCustom
// break;
case 102: //iDEMA
Execute_iDEMA();
break;
case 103: //iDeMarker
Execute_iDeMarker();
break;
case 104: //iEnvelopes
Execute_iEnvelopes();
break;
case 105: //iForce
Execute_iForce();
break;
case 106: //iFractals
Execute_iFractals();
break;
case 107: //iFrAMA
Execute_iFrAMA();
break;
case 108: //iGator
Execute_iGator();
break;
case 109: //iIchimoku
Execute_iIchimoku();
break;
case 110: //iBWMFI
Execute_iBWMFI();
break;
case 111: //iMomentum
Execute_iMomentum();
break;
case 112: //iMFI
Execute_iMFI();
break;
case 113: //iMA
Execute_iMA();
break;
case 114: //iOsMA
Execute_iOsMA();
break;
case 115: //iMACD
Execute_iMACD();
break;
case 116: //iOBV
Execute_iOBV();
break;
case 117: //iSAR
Execute_iSAR();
break;
case 118: //iRSI
Execute_iRSI();
break;
case 119: //iRVI
Execute_iRVI();
break;
case 120: //iStdDev
Execute_iStdDev();
break;
case 121: //iStochastic
Execute_iStochastic();
break;
case 122: //iTEMA
Execute_iTEMA();
break;
case 123: //iTriX
Execute_iTriX();
break;
case 124: //iWPR
Execute_iWPR();
break;
case 125: //iVIDyA
Execute_iVIDyA();
break;
case 126: //iVolumes
Execute_iVolumes();
break;
default:
Print("Unknown command type = ", commandType);
sendVoidResponse(ExpertHandle, _response_error);
break;
}
return (commandType);
}
void Execute_Request()
{
string request;
StringInit(request, 1000, 0);
if (!getStringValue(ExpertHandle, 0, request, _error))
{
PrintParamError("Request", "Request", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
string response = "";
if (request != "")
{
#ifdef __DEBUG_LOG__
Print("Execute_Request: incoming request = ", request);
#endif
response = OnRequest(request);
}
if (!sendStringResponse(ExpertHandle, response, _response_error))
{
PrintResponseError("Request", _response_error);
}
}
void Execute_OrderSend()
{
MqlTradeRequest request={0};
ReadMqlTradeRequestFromCommand(request);
MqlTradeResult result={0};
bool retVal = OrderSend(request, result);
if (!sendStringResponse(ExpertHandle, ResultToString(retVal, result), _response_error))
{
PrintResponseError("OrderSend", _response_error);
}
}
void Execute_OrderCloseAll()
{
if (!sendBooleanResponse(ExpertHandle, OrderCloseAll(), _response_error))
{
PrintResponseError("OrderCloseAll", _response_error);
}
}
void Execute_PositionClose()
{
ulong ticket;
ulong deviation;
CTrade trade;
if (!getULongValue(ExpertHandle, 0, ticket, _error))
{
PrintParamError("PositionClose", "ticket", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getULongValue(ExpertHandle, 1, deviation, _error))
{
PrintParamError("PositionClose", "deviation", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!sendBooleanResponse(ExpertHandle, trade.PositionClose(ticket, deviation), _response_error))
{
PrintResponseError("PositionClose", _response_error);
}
}
void Execute_OrderCalcMargin()
{
int action;
string symbol;
double volume;
double price;
StringInit(symbol, 100, 0);
if (!getIntValue(ExpertHandle, 0, action, _error))
{
PrintParamError("OrderCalcMargin", "action", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getStringValue(ExpertHandle, 1, symbol, _error))
{
PrintParamError("OrderCalcMargin", "symbol", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getDoubleValue(ExpertHandle, 2, volume, _error))
{
PrintParamError("OrderCalcMargin", "volume", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getDoubleValue(ExpertHandle, 3, price, _error))
{
PrintParamError("OrderCalcMargin", "price", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
double margin;
bool retVal = OrderCalcMargin((ENUM_ORDER_TYPE)action, symbol, volume, price, margin);
if (!sendStringResponse(ExpertHandle, ResultToString(retVal, margin), _response_error))
{
PrintResponseError("OrderCalcMargin", _response_error);
}
}
void Execute_OrderCalcProfit()
{
int action;
string symbol;
double volume;
double price_open;
double price_close;
StringInit(symbol, 100, 0);
if (!getIntValue(ExpertHandle, 0, action, _error))
{
PrintParamError("OrderCalcProfit", "action", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getStringValue(ExpertHandle, 1, symbol, _error))
{
PrintParamError("OrderCalcProfit", "symbol", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getDoubleValue(ExpertHandle, 2, volume, _error))
{
PrintParamError("OrderCalcProfit", "volume", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getDoubleValue(ExpertHandle, 3, price_open, _error))
{
PrintParamError("OrderCalcProfit", "price_open", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!getDoubleValue(ExpertHandle, 4, price_close, _error))
{
PrintParamError("OrderCalcProfit", "price_close", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
double profit;
bool retVal = OrderCalcProfit((ENUM_ORDER_TYPE)action, symbol, volume, price_open, price_close, profit);
if (!sendStringResponse(ExpertHandle, ResultToString(retVal, profit), _response_error))
{
PrintResponseError("OrderCalcProfit", _response_error);
}
}
void Execute_OrderCheck()
{
MqlTradeRequest request={0};
ReadMqlTradeRequestFromCommand(request);
MqlTradeCheckResult result={0};
bool retVal = OrderCheck(request, result);
if (!sendStringResponse(ExpertHandle, ResultToString(retVal, result), _response_error))
{
PrintResponseError("OrderCheck", _response_error);
}
}
void Execute_PositionsTotal()
{
if (!sendIntResponse(ExpertHandle, PositionsTotal(), _response_error))
{
PrintResponseError("PositionsTotal", _response_error);
}
}
void Execute_PositionGetSymbol()
{
int index;
if (!getIntValue(ExpertHandle, 0, index, _error))
{
PrintParamError("PositionGetSymbol", "index", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!sendStringResponse(ExpertHandle, PositionGetSymbol(index), _response_error))
{
PrintResponseError("PositionGetSymbol", _response_error);
}
}
void Execute_PositionSelect()
{
string symbol;
StringInit(symbol, 100, 0);
if (!getStringValue(ExpertHandle, 0, symbol, _error))
{
PrintParamError("PositionSelect", "symbol", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!sendBooleanResponse(ExpertHandle, PositionSelect(symbol), _response_error))
{
PrintResponseError("PositionSelect", _response_error);
}
}
void Execute_PositionGetDouble()
{
int property_id;
if (!getIntValue(ExpertHandle, 0, property_id, _error))
{
PrintParamError("PositionGetDouble", "property_id", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!sendDoubleResponse(ExpertHandle, PositionGetDouble((ENUM_POSITION_PROPERTY_DOUBLE)property_id), _response_error))
{
PrintResponseError("PositionGetDouble", _response_error);
}
}
void Execute_PositionGetInteger()
{
int property_id;
if (!getIntValue(ExpertHandle, 0, property_id, _error))
{
PrintParamError("PositionGetInteger", "property_id", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!sendLongResponse(ExpertHandle, PositionGetInteger((ENUM_POSITION_PROPERTY_INTEGER)property_id), _response_error))
{
PrintResponseError("PositionGetInteger", _response_error);
}
}
void Execute_PositionGetString()
{
int property_id;
if (!getIntValue(ExpertHandle, 0, property_id, _error))
{
PrintParamError("PositionGetString", "property_id", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!sendStringResponse(ExpertHandle, PositionGetString((ENUM_POSITION_PROPERTY_STRING)property_id), _response_error))
{
PrintResponseError("PositionGetString", _response_error);
}
}
void Execute_OrdersTotal()
{
if (!sendIntResponse(ExpertHandle, OrdersTotal(), _response_error))
{
PrintResponseError("OrdersTotal", _response_error);
}
}
void Execute_OrderGetTicket()
{
int index;
if (!getIntValue(ExpertHandle, 0, index, _error))
{
PrintParamError("OrderGetTicket", "index", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!sendULongResponse(ExpertHandle, OrderGetTicket(index), _response_error))
{
PrintResponseError("OrderGetTicket", _response_error);
}
}
void Execute_OrderSelect()
{
ulong ticket;
if (!getULongValue(ExpertHandle, 0, ticket, _error))
{
PrintParamError("OrderSelect", "ticket", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}
if (!sendBooleanResponse(ExpertHandle, OrderSelect(ticket), _response_error))
{
PrintResponseError("OrderSelect", _response_error);
}
}
void Execute_OrderGetDouble()
{
int property_id;
if (!getIntValue(ExpertHandle, 0, property_id, _error))
{
PrintParamError("OrderGetDouble", "property_id", _error);
sendErrorResponse(ExpertHandle, -1, _error, _response_error);
return;
}