Code Library / RSI Strategies

MQL5 RSI Overbought/Oversold EA

MQL5 EA trading RSI overbought and oversold levels.

Language: MQL5 · Category: RSI Strategies · Tags: RSI, overbought, oversold, MQL5, EA

Source code

#include <Trade/Trade.mqh>
CTrade trade; input int RSIPeriod=14; input double Lots=0.1;
void OnTick() {
   double rsi[]; int h=iRSI(_Symbol,PERIOD_CURRENT,RSIPeriod,PRICE_CLOSE);
   CopyBuffer(h,0,0,3,rsi); double pt=SymbolInfoDouble(_Symbol,SYMBOL_POINT);
   if(rsi[1]<30&&rsi[0]>=30&&PositionsTotal()==0)
      trade.Buy(Lots,_Symbol,0,SymbolInfoDouble(_Symbol,SYMBOL_ASK)-50*pt,SymbolInfoDouble(_Symbol,SYMBOL_ASK)+100*pt);
   if(rsi[1]>70&&rsi[0]<=70&&PositionsTotal()==0)
      trade.Sell(Lots,_Symbol,0,SymbolInfoDouble(_Symbol,SYMBOL_BID)+50*pt,SymbolInfoDouble(_Symbol,SYMBOL_BID)-100*pt);
   IndicatorRelease(h);
}

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own MQL5 project, compile it, and test it on a demo account with your broker's real spreads before relying on it. If MetaEditor reports errors, the compilation error fixer can help.

Related snippets