-
Notifications
You must be signed in to change notification settings - Fork 49
/
Sclab-inputsEnum.mq5
47 lines (39 loc) · 1.72 KB
/
Sclab-inputsEnum.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
#include <Trade\Trade.mqh>
CTrade trade;
input int ma_periodo = 20;//Período da Média
input int ma_desloc = 0;//Deslocamento da Média
input ENUM_MA_METHOD ma_metodo = MODE_SMA;//Método Média Móvel
input ENUM_APPLIED_PRICE ma_preco = PRICE_CLOSE;//Preço para Média
input ulong magicNum = 123456;//Magic Number
input ulong desvPts = 50;//Desvio em Pontos
input ENUM_ORDER_TYPE_FILLING preenchimento = ORDER_FILLING_RETURN;//Preenchimento da Ordem
input double lote = 5.0;//Volume
input double stopLoss = 5;//Stop Loss
input double takeProfit = 5;//Take Profit
double ask, bid, last;
double smaArray[];
int smaHandle;
int OnInit()
{
smaHandle = iMA(_Symbol, _Period, ma_periodo, ma_desloc, ma_metodo, ma_preco);
ArraySetAsSeries(smaArray, true);
trade.SetTypeFilling(preenchimento);
trade.SetDeviationInPoints(desvPts);
trade.SetExpertMagicNumber(magicNum);
return(INIT_SUCCEEDED);
}
void OnTick()
{
ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
last = SymbolInfoDouble(_Symbol, SYMBOL_LAST);
CopyBuffer(smaHandle, 0, 0, 3, smaArray);
if(last>smaArray[0] && PositionsTotal()==0)
{
trade.Buy(lote, _Symbol, ask, ask-stopLoss, ask+takeProfit, "");
}
else if(last<smaArray[0] && PositionsTotal()==0)
{
trade.Sell(lote, _Symbol, bid, bid+stopLoss, bid-takeProfit, "");
}
}