-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathPROphet.mq4
154 lines (127 loc) · 11.4 KB
/
PROphet.mq4
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
//+------------------------------------------------------------------+
//| PROphet.mq4 |
//| PraVedNiK |
//| [email protected] |
//+------------------------------------------------------------------+
/* EURUSD M5
包含两个相互独立的线性感知器(Perceptron).
它们中的每个都把输入烛形的属性分为两类.
class № 1 : BUY 并且 class № 2: flat(平) 或者 sell SELL
class № 1: SELL 并且 class № 2: flat 或者 BUY
这是 EA 的特点 - 一个感知器中不会只有BUY或者SELL的类别 !
在前12周进行了优化, 在周末分为两个阶段.
阶段 № 1:
设置变量 daBUY=true 而 daSELL=false , 权重
x1,x2,x3,x4 在 1~200 之间做优化, 预先设置的止损在 30~100 之间做优化, 第一阶段结束.
阶段 № 2:
设置变量 daBUY=false 而 daSELL=true, 权重
y1,y2,y3,y4 在 1~200 之间做优化, 可移动止损在 30~100 之间做优化.
在优化完毕之后, 把变量 daBUY 和 daSELL 设为 true.
取得的值可以用于下个 (未来的) 星期.
每个星期过去都要进行参数的调整.
*/
#property link "[email protected]"
extern double lot=0.1;
//--------------------------------------------------------------------
extern bool daBUY=true; extern int x1=9,x2=29,x3=94,x4=125,slb=68;
//---------------------------------------------------------------------------
extern bool daSELL=true; extern int y1=61,y2=100,y3=117,y4=31,sls=72;
extern int StartH=10, EndH=18;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//-----For M5_EURUSD------
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
//--------------------------------------------------------------------
static int prevtime=0; int ticket=0;
//-----------------------------------------------------------------
int start()
{
if(Time[0]==prevtime) return(0); prevtime=Time[0];
if(!IsTradeAllowed()) { prevtime=Time[1]; MathSrand(TimeCurrent());Sleep(30000+MathRand());}
//-------------------------------------------------------------------------------------------------
int total=OrdersTotal(); if(daBUY)BBB(total);if(daSELL)SSS(total); return(0);
} //--end_start--
//-------------------------------------------------------------------------------------------
void BBB(int tot)
{
int sprb=MarketInfo(Symbol(),MODE_SPREAD)+2*slb; int h=Hour();
for(int i=0; i<tot; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==74)
{//--------------------
if(OrderType()==OP_BUY && h>EndH)OrderClose(OrderTicket(),OrderLots(),Bid,3);
//----------------------------------------------------------------------------------
if(Bid>(OrderStopLoss()+sprb*Point) && OrderType()==OP_BUY)
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-slb*Point,0,0,Blue))
{Sleep(30000);prevtime=Time[1];}
}
//----------------------------------------------------------------------------------
return(0);
}
}//-----------------------------------------------------------------------------------------
ticket=-1; RefreshRates();
//-----------------------------------------------------------------------------------------
if(Qu(x1,x2,x3,x4)>0 && h>=StartH && h<=EndH && IsTradeAllowed())
{
ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,4,Bid-slb*Point,0,"buy",74,0,Blue);
PlaySound("news.wav");
if(ticket<0) { Sleep(30000);prevtime=Time[1]; }
} //-- Exit -
return(0);
}
//-------------------------------------------------------------------------------------------
void SSS(int tot)
{
int sprs=MarketInfo(Symbol(),MODE_SPREAD)+2*sls; int h=Hour();
for(int i=0; i<tot; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==81)
{//--------------------
if(OrderType()==OP_SELL && h>EndH)OrderClose(OrderTicket(),OrderLots(),Ask,3);
//----------------------------------------------------------------------------------
if(Ask<(OrderStopLoss()-sprs*Point) && OrderType()==OP_SELL)
{
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+sls*Point,0,0,Blue))
{Sleep(30000); prevtime=Time[1];}
}
return(0);
}
}//-----------------------------------------------------------------------------------------
ticket=-1; RefreshRates();
//-----------------------------------------------------------------------------------------
if(Qu(y1,y2,y3,y4)>0 && h>=StartH && h<=EndH && IsTradeAllowed())
{
ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,4,Ask+sls*Point,0,"sell",81,0,Red);
PlaySound("news.wav");
if(ticket<0) { Sleep(30000); prevtime=Time[1];}
} //-- Exit -
return(0);
}
//=====================================================================================================
double Qu(int q1,int q2,int q3,int q4)
{
return((q1-100)*MathAbs(High[1]-Low[2])+
(q2-100)*MathAbs(High[3]-Low[2])+(q3-100)*MathAbs(High[2]-Low[1])+(q4-100)*MathAbs(High[2]-Low[3]));
}
//+------------------------------------------------------------------+