Code Library / RSI Strategies
MQL5 RSI Range Trading
RSI range-bound trading for sideways markets.
Language: MQL5 · Category: RSI Strategies · Tags: RSI, range trading, MQL5, sideways, mean reversion
Source code
#include <Trade/Trade.mqh>
CTrade trade;
void RSIRange(int rsiP, double lots) {
double rsi[],adx[]; int rH=iRSI(_Symbol,PERIOD_CURRENT,rsiP,PRICE_CLOSE);
int aH=iADX(_Symbol,PERIOD_CURRENT,14); CopyBuffer(rH,0,0,3,rsi); CopyBuffer(aH,0,0,1,adx);
if(adx[0]>=25) return;
if(rsi[1]<30&&rsi[0]>30&&PositionsTotal()==0) trade.Buy(lots,_Symbol);
IndicatorRelease(rH); IndicatorRelease(aH);
}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.