Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 5 Expert Advisor | Gold90

MetaTrader Experts, Indicators, Scripts and Libraries
# Updated EA code using 1-hour timeframe instead of PERIOD_M90
ea_code_h1 = """
//+------------------------------------------------------------------+
//|                                                  Gold90EA_H1.mq5 |
//|      MQL5 EA using H1 timeframe for RSI and Bollinger Bands     |
//+------------------------------------------------------------------+
#property strict
#include <Trade/Trade.mqh>
input double LotSize          = 0.40;
input double RebuyMultiplier = 1.5;
input double PartialTP       = 9.0;
input double FullTP          = 22.0;
input double RebuyDrop       = 10.0;
input int    RSI_Period      = 14;
input int    BB_Period       = 20;
input double BB_Dev          = 2.0;
input double RSI_TriggerLow  = 30.0;
input double RSI_TriggerHigh = 31.5;
input double BB_Tolerance    = 4.0;
CTrade trade;
double entryPrice = 0;
bool partialTPHit = false;
bool fullTPHit = false;
bool rebuyPlaced = false;
int rsiHandle;
int bbHandle;
int OnInit()
   rsiHandle = iRSI(_Symbol, PERIOD_H1, RSI_Period, PRICE_CLOSE);
   bbHandle = iBands(_Symbol, PERIOD_H1, BB_Period, BB_Dev, 0, PRICE_CLOSE);
   if(rsiHandle == INVALID_HANDLE || bbHandle == INVALID_HANDLE)
      Print("Indicator handle creation failed");
      return(INIT_FAILED);
   return(INIT_SUCCEEDED);
void OnTick()
   double rsiBuffer[1];
   double bbLowerBuffer[1];
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   if(CopyBuffer(rsiHandle, 0, 0, 1, rsiBuffer) <= 0 ||
      CopyBuffer(bbHandle, 2, 0, 1, bbLowerBuffer) <= 0)
     return;
   double rsi = rsiBuffer[0];
   double bbLower = bbLowerBuffer[0];
   bool rsiCrossed = (rsi > RSI_TriggerLow && rsi <= RSI_TriggerHigh);
   bool priceNearBB = bid <= (bbLower + BB_Tolerance);
   if (PositionsTotal() == 0 && rsiCrossed && priceNearBB)
      if (trade.Buy(LotSize, _Symbol, bid, 0, 0, "Gold90 Entry"))
        {
         entryPrice = bid;
         rebuyPlaced = false;
         partialTPHit = false;
         fullTPHit = false;
        }
   if (PositionsTotal() > 0 && !rebuyPlaced && bid <= (entryPrice - RebuyDrop))
      trade.Buy(LotSize * RebuyMultiplier, _Symbol, bid, 0, 0, "Gold90 Rebuy");
      rebuyPlaced = true;
   if (PositionsTotal() > 0 && !partialTPHit && bid >= (entryPrice + PartialTP))
      for (int i = PositionsTotal() - 1; i >= 0; i--)
        {
         if (PositionGetTicket(i))
           {
            double volume = PositionGetDouble(POSITION_VOLUME);
            trade.PositionClosePartial(_Symbol, volume * 0.66);
            partialTPHit = true;
           }
        }
      entryPrice = bid;
   if (partialTPHit && !fullTPHit && bid <= entryPrice)
      trade.PositionClose(_Symbol);
   if (!fullTPHit && bid >= (entryPrice + FullTP))
      trade.PositionClose(_Symbol);
      fullTPHit = true;
# Save the updated H1 version to file
h1_ea_file_path = "/mnt/data/Gold90EA_H1.mq5"
with open(h1_ea_file_path, "w") as f:
    f.write(ea_code_h1)
h1_ea_file_path
60972