//+------------------------------------------------------------------+ // ScalpingEA.mq5…
- User
//+------------------------------------------------------------------+ //| ScalpingEA.mq5 | //| Copyright 2024, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property strict
// Input parameters for the expert input double lotSize = 0.1; input int emaPeriod = 5; input int smaPeriod = 20; input int rsiPeriod = 14; input int bollingerPeriod = 20; input double bollingerDeviation = 2.0; input double stopLossPips = 10; input double takeProfitPips = 20;
// Handles for the indicators int EMAHandle; int SMAHandle; int RSIHandle; int BBHandle;
// Define ORDER_BUY and ORDER_SELL if not already defined #ifndef ORDER_BUY #define ORDER_BUY 0 #endif
#ifndef ORDER_SELL #define ORDER_SELL 1 #endif
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Initialize the indicators 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); BBHandle = iBands(_Symbol, _Period, bollingerPeriod, 0, bollingerDeviation, PRICE_CLOSE);
// Check if the indicators were created successfully if (EMAHandle == INVALID_HANDLE || SMAHandle == INVALID_HANDLE || RSIHandle == INVALID_HANDLE || BBHandle == INVALID_HANDLE) { Print("Erro ao criar os indicadores."); return (INIT_FAILED); }
return (INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Release the indicator handles IndicatorRelease(EMAHandle); IndicatorRelease(SMAHandle); IndicatorRelease(RSIHandle); IndicatorRelease(BBHandle); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { double emaCurrent = 0.0; double smaCurrent = 0.0; double rsiCurrent = 0.0; double bbUpperCurrent = 0.0, bbLowerCurrent = 0.0; double bandsBuffer[];
if (CopyBuffer(EMAHandle, 0, 0, 1, bandsBuffer) > 0) emaCurrent = bandsBuffer[0]; if (CopyBuffer(SMAHandle, 0, 0, 1, bandsBuffer) > 0) smaCurrent = bandsBuffer[0]; if (CopyBuffer(RSIHandle, 0, 0, 1, bandsBuffer) > 0) rsiCurrent = bandsBuffer[0]; if (CopyBuffer(BBHandle, 0, 0, 1, bandsBuffer) > 0) bbUpperCurrent = bandsBuffer[0]; if (CopyBuffer(BBHandle, 1, 0, 1, bandsBuffer) > 0) bbLowerCurrent = bandsBuffer[0];
- Assistant