-
Notifications
You must be signed in to change notification settings - Fork 0
/
TOO.mqh
88 lines (81 loc) · 3.16 KB
/
TOO.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
//+------------------------------------------------------------------+
//| TOO.mqh |
//| Dominik Liehr |
//| http://www.idragon.de |
//+------------------------------------------------------------------+
#property copyright "Dominik Liehr"
#property link "http://www.idragon.de"
#property strict
//+------------------------------------------------------------------+
//| defines |
//+------------------------------------------------------------------+
// #define MacrosHello "Hello, world!"
// #define MacrosYear 2010
//+------------------------------------------------------------------+
//| DLL imports |
//+------------------------------------------------------------------+
// #import "user32.dll"
// int SendMessageA(int hWnd,int Msg,int wParam,int lParam);
// #import "my_expert.dll"
// int ExpertRecalculate(int wParam,int lParam);
// #import
//+------------------------------------------------------------------+
//| EX5 imports |
//+------------------------------------------------------------------+
// #import "stdlib.ex5"
// string ErrorDescription(int error_code);
// #import
//+------------------------------------------------------------------+
int sendTrade(int cmd, double price, double volume, int slippage) {
int ticket = 0;
int n = OrdersTotal();
while(OrdersTotal() != (n+1)) {
if(IsTradeAllowed() && IsTradeContextBusy() == false) {
// Versuche, Trade auszuführen
ticket = OrderSend(Symbol(), cmd, volume, price, slippage, 0.0, 0.0, "");
// Fehler entstanden?
if(GetLastError() > 0) {
Print("Fehler: " + IntegerToString(GetLastError()));
}
} else {
// warte 100 ms
Sleep(100);
}
}
return(ticket);
}
bool closeTrade(int ticket) {
bool success = false;
int n = OrdersTotal();
// Versuche Trade zu schließen
while(OrdersTotal() != (n-1)) {
// Trade-Markt verfügbar?
if(IsTradeAllowed() && IsTradeContextBusy() == false) {
// Versuche Trade zu selektieren
if(OrderSelect(ticket, SELECT_BY_TICKET)) {
OrderClose(ticket, OrderLots(), OrderClosePrice(), 10);
}
} else {
// warte 100 ms
Sleep(100);
}
}
return(success);
}
void closeAllOrders() {
// schließe alle trades
while(OrdersTotal() > 0) {
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)) {
if(OrderType()==OP_BUY || OrderType()==OP_SELL){
if(IsTradeAllowed() && IsTradeContextBusy() == false) {
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),666,CLR_NONE);
}
} else {
if(IsTradeAllowed() && IsTradeContextBusy() == false) {
OrderDelete(OrderTicket());
}
}
}
Sleep(100);
}
}