Code Library / Support/Resistance

MQL5 Support Resistance Zones

Auto-detect S/R zones from pivot highs and lows.

Language: MQL5 · Category: Support/Resistance · Tags: support, resistance, zones, MQL5, pivots

Source code

struct SR { double price; int touches; bool isSupport; };
void FindSR(SR &levels[],int lookback,double zonePips) {
   double h[],l[]; CopyHigh(_Symbol,PERIOD_H1,0,lookback,h); CopyLow(_Symbol,PERIOD_H1,0,lookback,l);
   double zone=zonePips*SymbolInfoDouble(_Symbol,SYMBOL_POINT); int cnt=0;
   for(int i=2;i<lookback-2;i++)
      if(h[i]>h[i-1]&&h[i]>h[i+1]) {
         ArrayResize(levels,cnt+1); levels[cnt].price=h[i]; levels[cnt].isSupport=false; cnt++;
      }
}

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