Introduction
Greetings, forex storm spotters! Picture the forex market as a wild frontier, with prices swirling like unpredictable weather patterns. The Doji EA is your high-tech weather radar, an MQL5 bot that scans for the Doji candlestick patternβa rare formation where open and close prices are equal, signaling market indecision. It marks these patterns with red arrows on the chart, like flagging a stormβs approach, but leaves trading decisions to you. This article is your spotterβs log, guiding you through the code with crystal-clear detail for beginners, a flow smoother than a gentle breeze, and examplesβlike spotting Doji on EURUSDβto keep you engaged. Weβll quote variables (e.g., "open") and functions (e.g., "OnInit()") for clarity, balancing pro insights with a sprinkle of charm. Ready to track those market storms? Letβs launch this Doji spotter!
Strategy Blueprint
The Doji EA automates pattern detection:
Pattern Detection: Identifies Doji candles where the open equals the close price on the latest completed bar.
Visualization: Marks Doji patterns with a red arrow at the candleβs low on the chart.
Purpose: Highlights indecision points for manual trading decisions, not executing trades, like a radar guiding a storm chaserβs strategy.
Features: Checks new bars to avoid false signals, with a simple, lightweight design. Itβs like a weather radar, pinpointing Doji patterns to guide traders through market turning points with precision.

Code Implementation
Letβs navigate the MQL5 code like storm spotters tracking a brewing tempest, building our Doji detector step by step. Weβll flow from setting up the radar to spotting the pattern, marking it, and cleaning up, with transitions as seamless as a clear horizon. Each section includes code blocks, detailed explanations of what weβre doing, and examples to keep you engaged, all while staying beginner-friendly and professional.
Step 1: Setting Up the Weather RadarβPreparing the EA
We start by rigging our radar station, defining the EAβs structure to spot Doji patterns.
//+------------------------------------------------------------------+
//| DOJI.mq5 |
//| Copyright 2024, ALLAN MUNENE MUTIIRIA. #@Forex Algo-Trader. |
//| https://youtube.com/@ForexAlgo-Trader? |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, ALLAN MUNENE MUTIIRIA. #@Forex Algo-Trader"
#property link "https://youtube.com/@ForexAlgo-Trader?"
#property description "======= IMPORTANT =======\n"
#property description "1. This is a FREE EA."
#property description "2. To get the source code of the EA, follow the Copyright link."
#property description "3. Incase of anything, contact developer via the link provided."
#property description "Hope you will enjoy the EA Logic.\n"
#property description "*** HAPPY TRADING! ***"
#property version "1.00"
int OnInit(){
return(INIT_SUCCEEDED);
}We set up our radar with a #property header, declaring the EA as a free offering by Allan in 2024 with a YouTube link, like calibrating our storm-tracking equipment. In "OnInit()", we return INIT_SUCCEEDED, signaling, βRadarβs online, ready to scan!β This minimal setup keeps the EA lightweight, priming it for Doji detection, like a spotter gearing up for a storm chase.
Step 2: Scanning for StormsβDetecting the Doji Pattern
With the radar set, we scan for Doji candles, like spotting a storm cloud on the horizon.
bool NewBar(){
static datetime priorTime = 0;
datetime currentTime = iTime(Symbol(),Period(),0);
bool result = (currentTime != priorTime);
priorTime = currentTime;
return (result);
}
int getDoji(){
datetime time = iTime(_Symbol,PERIOD_CURRENT,1);
double open = iOpen(_Symbol,PERIOD_CURRENT,1);
double high = iHigh(_Symbol,PERIOD_CURRENT,1);
double low = iLow(_Symbol,PERIOD_CURRENT,1);
double close = iClose(_Symbol,PERIOD_CURRENT,1);
if (open == close){
Print("DOJI PATTERN FORMED");
createOBJECT(time,low,217,clrRed,"DOJI");
}
return 0;
}
void OnTick(){
if (!NewBar()) return;
Print("NEW BAR");
getDoji();
}In "OnTick()", we use "NewBar()" with "iTime()", "priorTime", and "currentTime" to process only new bars, avoiding duplicate checks, like scanning the sky at dawn. In "getDoji()", we grab the latest completed barβs data (bar 1) using "iTime()", "iOpen()", "iHigh()", "iLow()", "iClose()". If "open == close", weβve found a Doji, logging with "Print()", (βDOJI PATTERN FORMEDβ), and calling "createOBJECT()" to mark it, like flagging a Doji on EURUSD at 1.2000. We return 0, like reporting clear skies if no Doji forms.
Step 3: Flagging the StormβMarking the Doji Pattern
Doji spotted? We mark it with a red arrow, like planting a warning flag for the storm.
void createOBJECT(datetime time, double price, int arrawCode, color clr, string text){
string objName = " ";
if (ObjectCreate(0,objName,OBJ_ARROW,0,time,price)){
ObjectSetInteger(0,objName,OBJPROP_ARROWCODE,arrawCode);
ObjectSetInteger(0,objName,OBJPROP_COLOR,clr);
}
}In "createOBJECT()", we create a red arrow (code 217) at the Dojiβs low using "ObjectCreate(OBJ_ARROW)", "ObjectSetInteger()", but note the "objName" is a blank space (" "), which may cause issues (see notes). The arrow marks the pattern, like a neon flag on EURUSDβs chart at 1.2000βs low, signaling indecision for traders to assess.
Step 4: Packing Up the RadarβCleaning Up
When the chase is over, we tidy up to leave the chart clean.
void OnDeinit(const int reason){
}In "OnDeinit()", we leave it empty, as no cleanup is coded, like leaving radar markers in place. We could add "ObjectsDeleteAll()" to clear arrows, like packing up gear, but for now, itβs a light cleanup, ready for the next storm.
Why This EAβs a Storm-Spotting Legend (and Keeps You Engaged!)
This EA is a pattern-spotting legend, detecting Doji candles like a radar tracking storm clouds, marking them with red arrows for manual trading decisions. Its lightweight design makes it easy to use, ready for enhancements like trading logic. Example? Spot a Doji on GBPUSD at 1.3500 after an uptrend, signaling a potential sell at resistance, or on EURUSD in a range for a continuation buyβpure storm-chasing gold! Beginners can follow, and pros can refine it, making it a must-have for pattern traders.
Putting It All Together
To launch this EA:
Open MetaEditor in MetaTrader 5 like setting up a weather station.
Paste the code, compile (F5), and check for typosβno spotter wants a faulty radar.
Drop the EA on your chart and watch for red arrows marking Doji patterns.
Use the Doji signals to inform manual trades, like chasing a stormβs path.
Test on a demo firstβreal pips deserve a practice chase!
Conclusion
Weβve crafted a Doji pattern storm spotter that detects market indecision, marks it with red arrows, and guides manual trading decisions. This MQL5 code is our weather radar, explained with detail to make you a pattern spotter, a touch of charm to keep you engaged, and flow to carry you like a clear horizon. Ready to track? Check our video guide on the website for a front-row seat to this storm-chasing mission. Now go hunt those market pauses! πͺοΈ
Disclaimer: Tradingβs like spotting a stormβthrilling but risky. Losses can exceed deposits. Test strategies on a demo account before going live.