//+------------------------------------------------------------------+
//| ScalpingEA.mq5 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
input double lotSize = 0.01; // Tamanho do lote
input double takeProfit = 5; // Take profit em pontos
input double stopLoss = 5; // Stop loss em pontos
input double maxSpread = 2.0; // Spread máximo permitido (pips)
input int magicNumber = 123456; // Número mágico para identificação
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Inicializações de rotina aqui
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Cleanup
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
static datetime lastOrderTime;
double currentSpread = (Ask - Bid) / _Point;
// Verifica se o spread é aceitável
if (currentSpread > maxSpread)
return;
// Verifica se já fez 5 ordens na vela atual
if (lastOrderTime != iTime(NULL, PERIOD_M1, 0))
{
lastOrderTime = iTime(NULL, PERIOD_M1, 0);
}
else
{
if (OrdersCount() >= 5)
return;
}
// Lógica de entrada
if (SignalBuy())
PlaceOrder(ORDER_BUY, lotSize, Ask, stopLoss, takeProfit);
else if (SignalSell())
PlaceOrder(ORDER_SELL, lotSize, Bid, stopLoss, takeProfit);
}
//+------------------------------------------------------------------+
//| Função de colocação de ordem |
//+------------------------------------------------------------------+
void PlaceOrder(enum ORDER_TYPE orderType, double lots, double price, double stopLossPts, double takeProfitPts)
{
double sl, tp;
if (orderType == ORDER_BUY)
{
sl = price - stopLossPts * _Point;
tp = price + takeProfitPts * _Point;
}
else
{
sl = price + stopLossPts * _Point;
tp = price - takeProfitPts * _Point;
}
// Configurar os parâmetros do pedido
MqlTradeRequest request;
MqlTradeResult result;
ZeroMemory(request);
ZeroMemory(result);
request.action = TRADE_ACTION_DEAL;
request.magic = magicNumber;
request.symbol = _Symbol;
request.volume = lots;
request.type = orderType;
request.price = price;
request.sl = sl;
request.tp = tp;
request.deviation = 10;
request.type_filling = ORDER_FILLING_FOK;
if (!OrderSend(request, result))
Print("Erro ao enviar ordem: ", result.retcode);
}
//+------------------------------------------------------------------+
//| Lógica de sinal - Exemplo simples de cruzamento de média |
//+------------------------------------------------------------------+
bool SignalBuy()
{
// Adicione sua lógica de compra aqui
return iClose(NULL, PERIOD_M1, 0) > iOpen(NULL, PERIOD_M1, 0);
}
bool SignalSell()
{
// Adicione sua lógica de venda aqui
return iClose(NULL, PERIOD_M1, 0) < iOpen(NULL, PERIOD_M1, 0);
}
//+------------------------------------------------------------------+
int OrdersCount()
{
int totalOrders = 0;
for (int i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i) && OrderMagicNumber() == magicNumber && OrderOpenTime() == lastOrderTime)
totalOrders++;
}
return totalOrders;
}
erro:
'enum' - unexpected token HFT_Wendel_00003.mq5 62 17
identifier 'ORDER_TYPE' already used HFT_Wendel_00003.mq5 62 22
'orderType' - '{' beginning bracket expected HFT_Wendel_00003.mq5 62 33
'Ask' - undeclared identifier HFT_Wendel_00003.mq5 35 28
'Bid' - undeclared identifier HFT_Wendel_00003.mq5 35 34
'ORDER_BUY' - undeclared identifier HFT_Wendel_00003.mq5 54 18
'Ask' - undeclared identifier HFT_Wendel_00003.mq5 54 38
'ORDER_SELL' - undeclared identifier HFT_Wendel_00003.mq5 56 18
'Bid' - undeclared identifier HFT_Wendel_00003.mq5 56 39
'ORDER_BUY' - undeclared identifier HFT_Wendel_00003.mq5 65 21
implicit enum conversion HFT_Wendel_00003.mq5 86 19
'OrderMagicNumber' - undeclared identifier HFT_Wendel_00003.mq5 119 29
')' - expression expected HFT_Wendel_00003.mq5 119 46
'OrderOpenTime' - undeclared identifier HFT_Wendel_00003.mq5 119 66
')' - expression expected HFT_Wendel_00003.mq5 119 80
'lastOrderTime' - undeclared identifier HFT_Wendel_00003.mq5 119 85