-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTresMedias.mq5
74 lines (64 loc) · 6.15 KB
/
TresMedias.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
64
65
66
67
68
69
70
71
72
73
74
//+------------------------------------------------------------------+
//| TresMedias.mq5 |
//| Abraão Moreira |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "Abraão Moreira"
#property link "[email protected]"
#property version "1.00"
#include <Trade\Trade.mqh>
CTrade trade;
//Parâmetros de entrada para três médias, da quantidade de papeis a serem negociados e dos niveis em pontos de sl e tp
input int smallerAvg = 3;
input int interAvg = 8;
input int biggerAvg = 21;
input double amount = 20;
input double sl = 150;
input double tp = 300;
int smallerAvgHandle = 0, interAvgHandle = 0, biggerAvgHandle = 0;
double smallerAvgBuffer[], interAvgBuffer[], biggerAvgBuffer[];
string trend = "";
double ask = 0, bid = 0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit() {
ArraySetAsSeries(smallerAvgBuffer, true);
ArraySetAsSeries(interAvgBuffer, true);
ArraySetAsSeries(biggerAvgBuffer, true);
smallerAvgHandle = iMA(_Symbol, _Period, smallerAvg, 0, MODE_SMA, PRICE_CLOSE);
interAvgHandle = iMA(_Symbol, _Period, interAvg, 0, MODE_SMA, PRICE_CLOSE);
biggerAvgHandle = iMA(_Symbol, _Period, biggerAvg, 0, MODE_SMA, PRICE_CLOSE);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick() {
CopyBuffer(smallerAvgHandle, 0, 0, 3, smallerAvgBuffer);
CopyBuffer(interAvgHandle, 0, 0, 3, interAvgBuffer);
CopyBuffer(biggerAvgHandle, 0, 0, 3, biggerAvgBuffer);
ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
if(PositionsTotal() == 0) {
if(smallerAvgBuffer[1] > interAvgBuffer[1] && smallerAvgBuffer[2] < interAvgBuffer[2]) {
trend = "bull";
}
if(smallerAvgBuffer[1] < interAvgBuffer[1] && smallerAvgBuffer[2] > interAvgBuffer[2]) {
trend = "bear";
}
if(interAvgBuffer[1] < biggerAvgBuffer[1] && interAvgBuffer[2] > biggerAvgBuffer[2] && trend == "bull"){
trade.Buy(amount, NULL, ask, ask - sl*_Point, ask + tp*_Point, "Compra");
}
if(interAvgBuffer[1] > biggerAvgBuffer[1] && interAvgBuffer[2] < biggerAvgBuffer[2] && trend == "bear"){
trade.Sell(amount, NULL, bid, bid + sl*_Point, bid - tp*_Point, "Venda");
}
}
}
//+------------------------------------------------------------------+