//±-----------------------------------------------------------------+ // ScalpingEA.mq5…
- User
//±-----------------------------------------------------------------+ //| ScalpingEA.mq5| //| Copyright 2024, MetaTrader 5 User | //| www.mql5.com | //±-----------------------------------------------------------------+ input double lotSize = 0.1; // Tamanho do lote input int emaPeriod = 5; // Período da EMA input int smaPeriod = 20; // Período da SMA input int rsiPeriod = 14; // Período do RSI input int bollingerPeriod = 20; // Período das Bandas de Bollinger input double bollingerDeviation = 2.0; // Desvio padrão das Bandas de Bollinger input int stopLossPips = 10; // Stop Loss em pips input int takeProfitPips = 20; // Take Profit em pips
int emaHandle; int smaHandle; int rsiHandle; int bollingerHandle;
//±-----------------------------------------------------------------+ //| Expert initialization function | //±-----------------------------------------------------------------+ int OnInit() { // Inicializa os indicadores emaHandle = iMA(_Symbol, _Period, emaPeriod, 0, MODE_EMA, PRICE_CLOSE); smaHandle = iMA(_Symbol, _Period, smaPeriod, 0, MODE_SMA, PRICE_CLOSE); rsiHandle = iRSI(_Symbol, _Period, rsiPeriod, PRICE_CLOSE); bollingerHandle = iBands(_Symbol, _Period, bollingerPeriod, 0, bollingerDeviation, PRICE_CLOSE);
if (emaHandle == INVALID_HANDLE || smaHandle == INVALID_HANDLE || rsiHandle == INVALID_HANDLE || bollingerHandle == INVALID_HANDLE) { Print("Erro ao criar handles dos indicadores"); return INIT_FAILED; } return INIT_SUCCEEDED;}
//±-----------------------------------------------------------------+ //| Expert deinitialization function | //±-----------------------------------------------------------------+ void OnDeinit(const int reason) { // Libera os handles dos indicadores IndicatorRelease(emaHandle); IndicatorRelease(smaHandle); IndicatorRelease(rsiHandle); IndicatorRelease(bollingerHandle); }
//±-----------------------------------------------------------------+ //| Expert tick function | //±-----------------------------------------------------------------+ void OnTick() { double emaValue, smaValue, rsiValue; double bollingerUpperValue, bollingerLowerValue;
// Arrays temporários para receber os valores dos indicadores double emaArray[1], smaArray[1], rsiArray[1]; double bollingerUpperArray[1], bollingerLowerArray[1]; // Atualiza os valores dos indicadores if (CopyBuffer(emaHandle, 0, 0, 1, emaArray) <= 0 || CopyBuffer(smaHandle, 0, 0, 1, smaArray) <= 0 || CopyBuffer(rsiHandle, 0, 0, 1, rsiArray) <= 0 || CopyBuffer(bollingerHandle, 1, 0, 1, bollingerUpperArray) <= 0 || CopyBuffer(bollingerHandle, 2, 0, 1, bollingerLowerArray) <= 0) { Print("Erro ao atualizar valores dos indicadores"); return; } emaValue = emaArray[0]; smaValue = smaArray[0]; rsiValue = rsiArray[0]; bollingerUpperValue = bollingerUpperArray[0]; bollingerLowerValue = bollingerLowerArray[0]; double currentPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID); // Verifica se já existe uma posição aberta if (PositionsTotal() == 0) { // Condições de Compra if (emaValue > smaValue && rsiValue < 70 && currentPrice < bollingerUpperValue) { OpenOrder(ORDER_TYPE_BUY, lotSize, stopLossPips, takeProfitPips); } // Condições de Venda if (emaValue < smaValue && rsiValue > 30 && currentPrice > bollingerLowerValue) { OpenOrder(ORDER_TYPE_SELL, lotSize, stopLossPips, takeProfitPips); } } - Assistant