Code Library / Candlestick Patterns
MQL5 Doji Detector
Detect Doji patterns including dragonfly and gravestone.
Language: MQL5 · Category: Candlestick Patterns · Tags: doji, candlestick, MQL5, pattern, indecision
Source code
enum DOJI {NONE,STD,DRAGON,GRAVE};
DOJI DetectDoji(int s) {
double o[],h[],l[],c[];
CopyOpen(_Symbol,PERIOD_CURRENT,s,1,o); CopyHigh(_Symbol,PERIOD_CURRENT,s,1,h);
CopyLow(_Symbol,PERIOD_CURRENT,s,1,l); CopyClose(_Symbol,PERIOD_CURRENT,s,1,c);
double body=MathAbs(c[0]-o[0]), range=h[0]-l[0];
if(range==0||body/range>0.1) return NONE;
double uw=h[0]-MathMax(o[0],c[0]), lw=MathMin(o[0],c[0])-l[0];
if(lw>range*0.6) return DRAGON;
if(uw>range*0.6) return GRAVE;
return STD;
}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.