Forex Algo Trader
Sign In Register
Market Resources Tools Autotrading Algo Jobs
Crafting a Doji Pattern Storm Spotter with MQL5 πŸŒͺ️
Resource

Crafting a Doji Pattern Storm Spotter with MQL5 πŸŒͺ️

Join us for a detailed, professional, and engaging journey through our MQL5 code that automates Doji candlestick pattern detection, marking market indecision points with red arrows for manual trading decisions. We’ll break down every step with code blocks, keep the flow as smooth as a clear horizon, and use examples to keep you sharpβ€”all while delivering a pro-level guide with a touch of charm! 😎
Allan Munene Mutiiria Verified
@allan_munene_mutiiria
1 year ago 441 views 0 comments 5 min read 2 files

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.

Attachments
DOJI.ex5 Β· 7.7 KB
Download
DOJI.mq5 Β· 2.2 KB
Download
441 views
Discussions 0

No discussions yet

Be the first to share your thoughts on this resource.

Sign in to take part
Sign in or register to comment and report.
0%
Uploading…
Please don’t close this page