Code Library / Support/Resistance
MQL5 Supply Demand Zones
Identify supply and demand zones from strong candles.
Language: MQL5 · Category: Support/Resistance · Tags: supply demand, zones, MQL5, institutional, order blocks
Source code
struct Zone { double top; double bot; bool isSupply; };
void FindZones(Zone &z[],int lookback) {
double o[],h[],l[],c[];
CopyOpen(_Symbol,PERIOD_CURRENT,0,lookback,o); CopyHigh(_Symbol,PERIOD_CURRENT,0,lookback,h);
CopyLow(_Symbol,PERIOD_CURRENT,0,lookback,l); CopyClose(_Symbol,PERIOD_CURRENT,0,lookback,c);
int cnt=0;
for(int i=1;i<lookback-1;i++) {
double body=MathAbs(c[i]-o[i]),range=h[i]-l[i];
if(range>0&&c[i]>o[i]&&body/range>0.6&&c[i]>h[i-1]) {
ArrayResize(z,cnt+1); z[cnt].top=o[i]; z[cnt].bot=l[i]; z[cnt].isSupply=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.