-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTripple Moving Average EA.mqh4
184 lines (162 loc) · 5.84 KB
/
Tripple Moving Average EA.mqh4
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
#property copyright "Andrey Bulezyuk"
#property link "https://www.in-trading.eu"
#property version "1.00"
#property strict
input double LotGroesse=0.1;
input int FilterMA=200;
input int HauptMA=50;
input int SignalMA=15;
input bool StopLossVerwenden=true;
input int StopLoss=500; //100=10Pips; 1000=100Pips
input bool TakeProfitVerwenden=true;
input int TakeProfit=1000; //100=10Pips; 1000=100Pips
input bool PrimaeresGegensignal=true;
int OnInit()
{
if(FilterMA<HauptMA || FilterMA<SignalMA)
{
Alert("Filter MA muss größer sein als HauptMA und SignalMA");
return(INIT_PARAMETERS_INCORRECT);
}
if(HauptMA<SignalMA)
{
Alert("SignalMA muss kleiner sein als HauptMA");
return(INIT_PARAMETERS_INCORRECT);
}
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
double FilterMAWert0 = iMA(Symbol(),Period(),FilterMA,0,0,0,0);
double SLTemp = 0.0;
double TPTemp = 0.0;
double HauptMAWert0=iMA(Symbol(),Period(),HauptMA,0,0,0,0);
double HauptMAWert1=iMA(Symbol(),Period(),HauptMA,0,0,0,1);
double SignalMAWert0=iMA(Symbol(),Period(),SignalMA,0,0,0,0);
double SignalMAWert1=iMA(Symbol(),Period(),SignalMA,0,0,0,1);
// wenn keine offene Positionen vorhanden sind
if(OrdersTotal() <= 0)
{
if(FilterMAWert0<HauptMAWert0) //Filter bullisch
{
if(SignalMAWert1<=HauptMAWert1 && SignalMAWert0>HauptMAWert0) //Signal bullisch
{
if(AccountFreeMarginCheck(Symbol(),0,LotGroesse) > 1) //Ausreichend Margin?
{
if(StopLossVerwenden==true)
{
SLTemp=Bid-StopLoss*Point;
}else{
SLTemp=0.0;
}
if(TakeProfitVerwenden==true)
{
TPTemp=Bid+TakeProfit*Point;
}else{
TPTemp=0.0;
}
if(OrderSend(Symbol(),OP_BUY,LotGroesse,Ask,0,SLTemp,TPTemp,"Tripple MA Strategie",12345,0,clrNONE) == true)
{
Alert("Long Position (Lot:"+LotGroesse+"|SL:"+SLTemp+"|TP:"+TPTemp+") eröffnet!");
}
}else{
Alert("Keine freie Margin nach Positionseröffnung!");
}
}
}else{// Filter bearisch
if(SignalMAWert1>HauptMAWert1 && SignalMAWert0<HauptMAWert0) //Signal bearisch
{
if(AccountFreeMarginCheck(Symbol(),1,LotGroesse) > 1) //Ausreichend Margin?
{
if(StopLossVerwenden==true)
{
SLTemp=Ask+StopLoss*Point;
}else{
SLTemp=0.0;
}
if(TakeProfitVerwenden==true)
{
TPTemp=Ask-TakeProfit*Point;
}else{
TPTemp=0.0;
}
if(OrderSend(Symbol(),OP_SELL,LotGroesse,Bid,0,SLTemp,TPTemp,"Tripple MA Strategie",12345,0,clrNONE)==true)
{
Alert("Short Position (Lot:"+LotGroesse+"|SL:"+SLTemp+"|TP:"+TPTemp+") eröffnet!");
}
}else{
Alert("Keine freie Margin nach Positionseröffnung!");
}
}
}
}
// Bei Signalgenerierung gegensätzliche Positionen schließen //
if(OrdersTotal() > 0)
{
if(PrimaeresGegensignal==true)
{
//Offene Positionen bei Gegensignal inkl. Filter schliessen//
if(FilterMAWert0<HauptMAWert0) //Filter bullisch
{
if(SignalMAWert1<HauptMAWert1 && SignalMAWert0>HauptMAWert0) //Signal bullisch -> Short schliessen
{
for(int a=0;a<OrdersTotal();a++)
{
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)) // Offene Position auswaehlen
{
if(OrderType()==1) // Wenn Short
{
OrderClose(OrderTicket(),OrderLots(),Ask,0,clrNONE); //Dann schliessen
}
}
}
}
}else{// Filter bearisch
if(SignalMAWert1>HauptMAWert1 && SignalMAWert0>HauptMAWert0) //Signal bearisch -> Long schliessen
{
for(int b=0;b<OrdersTotal();b++)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) // Offene Position auswaehlen
{
if(OrderType()==0) // Wenn Long
{
OrderClose(OrderTicket(),OrderLots(),Bid,0,clrNONE); //Dann schliessen
}
}
}
}
}
}else{
//Offene Positionen bei Gegensignal exkl. Filter schliessen//
if(SignalMAWert1<HauptMAWert1 && SignalMAWert0>HauptMAWert0) //Signal bullisch -> Short schliessen
{
for(int a=0;a<OrdersTotal();a++)
{
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)) // Offene Position auswaehlen
{
if(OrderType()==1) // Wenn Short
{
OrderClose(OrderTicket(),OrderLots(),Ask,0,clrNONE); //Dann schliessen
}
}
}
}
if(SignalMAWert1>HauptMAWert1 && SignalMAWert0<HauptMAWert0) //Signal bearisch -> Long schliessen
{
for(int b=0;b<OrdersTotal();b++)
{
if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) // Offene Position auswaehlen
{
if(OrderType()==0) // Wenn Long
{
OrderClose(OrderTicket(),OrderLots(),Bid,0,clrNONE); //Dann schliessen
}
}
}
}
}
}
}