Viewing the resource: Crafting a Doji Pattern Storm Spotter with MQL5 🌪️

Crafting a Doji Pattern Storm Spotter with MQL5 🌪️

Allan Munene Mutiiria 2025-06-21 17:05:55 90 Views
Join us for a detailed, professional, and engaging journey through our MQL5 code that automates Doji...

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:

  1. Open MetaEditor in MetaTrader 5 like setting up a weather station.

  2. Paste the code, compile (F5), and check for typos—no spotter wants a faulty radar.

  3. Drop the EA on your chart and watch for red arrows marking Doji patterns.

  4. Use the Doji signals to inform manual trades, like chasing a storm’s path.

  5. 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.

Attached Files

Disclaimer: The ideas and strategies presented in this resource are solely those of the author and are intended for informational and educational purposes only. They do not constitute financial advice, and past performance is not indicative of future results. All materials, including but not limited to text, images, files, and any downloadable content, are protected by copyright and intellectual property laws and are the exclusive property of Forex Algo-Trader or its licensors. Reproduction, distribution, modification, or commercial use of these materials without prior written consent from Forex Algo-Trader is strictly prohibited and may result in legal action. Users are advised to exercise extreme caution, perform thorough independent research, and consult with qualified financial professionals before implementing any trading strategies or decisions based on this resource, as trading in financial markets involves significant risk of loss.

Recent Comments

Go to discussion to Comment or View other Comments

No comments yet. Be the first to comment!