-
Notifications
You must be signed in to change notification settings - Fork 0
/
a
150 lines (133 loc) · 5.45 KB
/
a
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
//+------------------------------------------------------------------+
//| newEA.mq4 |
//| Copyright 2021, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
input int MagicNum=12;
input double lot=0.01;
input int MaxDanShu=9;
input int 止盈点数=3000;
input int 加仓点数=3000;
input int xau止盈点数=3000;
input int xau加仓点数=3000;
input int gbp止盈点数=100;
input int gbp加仓点数=100;
input int 点差=300;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
Print("开始智能交易");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
Print("结束智能交易");
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
int buy_count=0;
double last_buy_open_price=0;
double last_buy_open_lot = 0;
int sell_count=0;
double last_sell_open_price=0;
double last_sell_open_lot = 0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNum)
{
if(OrderType()==OP_BUY)
{
buy_count = buy_count + 1;
last_buy_open_price = OrderOpenPrice();
last_buy_open_lot = OrderLots();
}
if(OrderType()==OP_SELL)
{
sell_count = sell_count + 1;
last_sell_open_price = OrderOpenPrice();
last_sell_open_lot = OrderLots();
}
}
}
Print("last_buy_open_price:"+last_buy_open_price);
Print("last_buy_open_lot:"+last_buy_open_lot);
Print("last_sell_open_price:"+last_sell_open_price);
Print("last_sell_open_lot:"+last_sell_open_lot);
if(buy_count==0 && buy_count<=MaxDanShu)
{
//开第一单
double stoploss = 0;
//double takeprofit = 0;
double takeprofit = NormalizeDouble(Ask+止盈点数*Point,Digits);
int ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,3,stoploss,takeprofit,"buy-"+IntegerToString(buy_count+1),MagicNum,0,clrNONE);
}
else
if(buy_count >=1 && buy_count<=MaxDanShu)
{
if(last_buy_open_price-Bid>=加仓点数*Point)
{
double takeprofit = NormalizeDouble(Ask+止盈点数*Point,Digits);
double lotbuy = last_buy_open_lot*2;
int ticket=OrderSend(Symbol(),OP_BUY,lotbuy,Ask,3,0,takeprofit,"buy-"+IntegerToString(buy_count+1),MagicNum,0,clrNONE);
//修改止盈
for(int j=0; j<OrdersTotal(); j++)
{
if(OrderSelect(j,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNum && OrderType()==OP_BUY)
{
//double stoploss = NormalizeDouble(Bid-Point*2000,Digits);
double stoploss = 0;
double takeprofit = NormalizeDouble(Ask+Point*止盈点数,Digits); //+Point*点差
bool mod_bool = OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,takeprofit,0,clrNONE);
Print(mod_bool);
}
}
}
}
if(sell_count==0 && sell_count<=MaxDanShu)
{
//开第一单
double stoploss = 0;
//double takeprofit = 0;
double takeprofit = NormalizeDouble(Bid-止盈点数*Point,Digits);
int ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,3,stoploss,takeprofit,"sell-"+IntegerToString(sell_count+1),MagicNum,0,clrNONE);
}
else
if(sell_count >=1 && sell_count<=MaxDanShu)
{
if(Ask-last_sell_open_price>=加仓点数*Point)
{
double takeprofit = NormalizeDouble(Bid-止盈点数*Point,Digits);
double lotsell = last_sell_open_lot*2;
int ticket=OrderSend(Symbol(),OP_BUY,lotsell,Bid,3,0,takeprofit,"sell-"+IntegerToString(sell_count+1),MagicNum,0,clrNONE);
//修改止盈
for(int j=0; j<OrdersTotal(); j++)
{
if(OrderSelect(j,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNum && OrderType()==OP_SELL)
{
//double stoploss = NormalizeDouble(Bid-Point*2000,Digits);
double stoploss = 0;
double takeprofit = NormalizeDouble(Bid-止盈点数*Point,Digits); //+Point*点差
bool mod_bool = OrderModify(OrderTicket(),OrderOpenPrice(),stoploss,takeprofit,0,clrNONE);
Print(mod_bool);
}
}
}
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+