/
FXEe.py
131 lines (124 loc) · 3.74 KB
/
FXEe.py
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
int sellMarket(double tradingLots,double stopLoss,double takeProfit,int expiration=0,color tradeColor=Red)
{
int ticket=OrderSend(Symbol(),OP_SELL,tradingLots,Bid,3,NormalizeDouble(stopLoss,Digits),NormalizeDouble(takeProfit,Digits),"Sell market trade",16384,expiration,tradeColor);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
{
Print("SELL order opened : ",OrderOpenPrice());
}
return ticket;
}
else
{
Print("Error opening SELL order : ",GetLastError());
return 0;
}
}
int modifyTrade(int ticket,double stopLoss,double takeProfit,int expiration=0,color modifyColor=Orange)
{
if(ticket>0)
{
if(OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(stopLoss,Digits),NormalizeDouble(takeProfit,Digits),expiration,modifyColor))
{
Print("Order "+IntegerToString(ticket)+" modified");
return ticket;
}
}
else
{
Print("[ERROR] Could not modify trade as no ticket number was found");
}
return 0;
}
//+------------------------------------------------------------------+
//| Close all open buy trades
//+------------------------------------------------------------------+
int closeAllBuys()
{
for(int i=0;i<OrdersTotal();i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
// could not find the order
Print("[ERROR] Could not find the order to monitor stop loss");
continue;
}
// if there is an open sell trade of this symbol
if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
{
int closeID=OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue);
if(!closeID)
{
Print("[ERROR] Could not close all buy trades | "+IntegerToString(GetLastError()));
return -1;
}
else
{
return closeID;
}
}
}
return -1;
}
//+------------------------------------------------------------------+
//| Close all open sell trades
//+------------------------------------------------------------------+
int closeAllSells()
{
for(int i=0;i<OrdersTotal();i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
// could not find the order
Print("[ERROR] Could not find the order to monitor stop loss");
continue;
}
// if there is an open sell trade of this symbol
if(OrderType()==OP_SELL && OrderSymbol()==Symbol())
{
int closeID=OrderClose(OrderTicket(),OrderLots(),Ask,3,Blue);
if(!closeID)
{
Print("[ERROR] Could not close all sell trades | "+IntegerToString(GetLastError()));
return -1;
}
else
{
return closeID;
}
}
}
return -1;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int findSellCount()
{
int tradeCount=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderType()==OP_SELL && OrderSymbol()==Symbol())
{
tradeCount++;
}
}
return tradeCount;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int findBuyCount()
{
int tradeCount=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderType()==OP_BUY && OrderSymbol()==Symbol())
{
tradeCount++;
}
}
return tradeCount;
}
//+------------------------------------------------------------------+