-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCandleBaseEA.mq5
63 lines (39 loc) · 1.42 KB
/
CandleBaseEA.mq5
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
#include<Trade\Trade.mqh>
CTrade trade;
//--input parameters
input int DirectionalPips=10;
input int TakeProfitPips=20;
input int StopLossPips=20;
input double LotSize=0.10;
input int MaximumPositions=10;
void OnTick()
{
string Trend="";
string signal="";
double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
//empty array for the prices
MqlRates PriceInfo[];
ArraySetAsSeries(PriceInfo,true);
int PriceData=CopyRates(_Symbol,_Period,0,10,PriceInfo);
//Status of the current to gauge the direction
double Difference= PriceInfo[9].close- PriceInfo[0].close;
//Trend direction According to the zero reference point
if(Difference>0)
Trend="Uptrend";
if(Difference<0)
Trend="Downtrend";
if(Trend=="Uptrend" && Difference>=DirectionalPips*_Point)
signal="buy";
if(Trend=="Downtrend" && Difference<=-DirectionalPips*_Point)
signal="sell";
//Sell and buy conditions met
if(signal=="sell" && PositionsTotal()<1)
trade.Sell(LotSize,NULL,Bid,(Bid+TakeProfitPips*_Point),(Bid-StopLossPips*_Point),"Sell condition met");
//Buy Condition
if(signal=="buy" && PositionsTotal()<1)
trade.Buy(LotSize,NULL,Ask,(Ask+TakeProfitPips*_Point),(Ask-StopLossPips*_Point),"Buy condition met");
//Postions management
if(PositionsTotal()<MaximumPositions)
trade.Close()
}