Introduction
Imagine youβre a cosmic storm spotter, standing on the bridge of your trading starship, scanning the forex galaxy for signs of a market shift. The Hanging Man EA is your high-tech radar, meticulously designed to detect the Hanging Man candlestick patternβa single candle that signals a potential bearish reversal after an uptrend. Picture a candle with a small body (open and close near the high) and a long lower wick, like a star dangling precariously before it falls, warning that buyers are losing steam. This EA doesnβt place trades but marks these patterns with white arrows on your chart, like planting beacons to guide your manual trading decisions. In this article, Iβll take you on a seamless, professional journey through the code, weaving a narrative that flows like a starry night sky. Each section will build on the last, with detailed explanations tailored for beginners, vibrant examples to bring the concepts to life, and a touch of cosmic charm to keep you captivated. Whether youβre new to MQL5 or a seasoned trader, this guide will illuminate how the EA spots Hanging Man patterns and sets you up to trade with precision. Letβs power up the radar and start our mission to hunt those bearish signals!
Strategy Blueprint
Before we dive into the code, letβs chart the course of what this EA does, like plotting a star map for our trading expedition:
Pattern Detection: The EA identifies a Hanging Man candle, where the open is above the close (bearish), the upper wick (high minus open) is less than 10% of the candleβs size, and the lower wick (close minus low) is over 70% of the size, signaling indecision after an uptrend.
Visualization: It places a white arrow at the candleβs low on the chart, acting as a clear visual cue for traders to spot potential sell opportunities.
Purpose: Designed for manual trading, the EA highlights bearish reversal points without executing trades, like a radar guiding your strategy without taking the helm.
Features: Processes the latest completed candle for accuracy, with a lightweight design thatβs easy to extend with trading logic if desired. This strategy is like a cosmic radar, pinpointing Hanging Man patterns to guide traders through market turning points with clarity and precision, making it an essential tool for spotting bearish reversals.

Code Implementation
Now, letβs step into the starshipβs engineering bay and explore the MQL5 code that powers this cosmic spotter. Iβll guide you through each section like a mission commander, ensuring the narrative flows seamlessly from one part to the next, with professional polish and engaging details. Weβll cover setting up the radar, detecting the Hanging Man pattern, marking it on the chart, and cleaning up, using clear explanations and examplesβlike spotting a Hanging Man on EURUSDβto make it relatable for beginners. Each step will feel like a chapter in our cosmic adventure, keeping you hooked as we build this trading tool together.
Step 1: Powering Up the Cosmic RadarβSetting the Stage
Our journey begins by activating the starshipβs radar system, laying the foundation for detecting Hanging Man patterns.
//+------------------------------------------------------------------+
//| hanging man.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 start by powering up the radar with the #property header, proudly declaring the EA as a free offering by Allan in 2024, complete with a YouTube link for support, like engraving your starshipβs mission badge. The "OnInit()" function is our launch sequence, where we flip the switch to get the EA ready. Itβs simple but effective, returning INIT_SUCCEEDED to signal, βRadarβs online, ready to scan the galaxy!β This minimal setup keeps the EA lightweight, like a sleek spaceship built for speed, priming it to detect Hanging Man patterns without any extra baggage. Think of it as setting up your control panel with just the essentials, ready to focus on spotting those cosmic signals.
Step 2: Scanning the StarfieldβDetecting the Hanging Man Pattern
With the radar humming, we turn our attention to scanning the forex galaxy for the Hanging Man pattern, like spotting a flickering star signaling a storm.
int getHangingMan(){
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);
double candleSize = high - low;
if (open > close){
if (high - open < candleSize * 0.1){
if (close - low > candleSize * 0.7){
Print("Hanging man pattern formed, SELL SIGNAL");
createOBJ(time,low,233,clrWhite);
}
}
}
return 0;
}
void OnTick(){
getHangingMan();
}Now, letβs move to the bridge of our starship, where the "OnTick()" function acts as our radarβs continuous scan, checking every price tick for action. It calls "getHangingMan()", which is the heart of our pattern detection, like tuning the radar to spot a specific cosmic signal. This function focuses on the latest completed candle (bar 1) to ensure the pattern is fully formed, avoiding false alerts.
In "getHangingMan()", we grab the candleβs data using "iTime()", "iOpen()", "iHigh()", "iLow()", and "iClose()", like pulling up a starβs coordinates. We calculate the candleβs size ("candleSize = high - low")βthink of this as measuring the starβs brightness range. The Hanging Man pattern requires three conditions:
The candle is bearish ("open > close"), meaning the price fell during the period, like a star dimming.
The upper wick is tiny ("high - open < candleSize * 0.1"), less than 10% of the candleβs size, showing little upward push.
The lower wick is long ("close - low > candleSize * 0.7"), over 70% of the size, indicating buyers tried to push up but failed.
If all conditions are met, we log the discovery with "Print("Hanging man pattern formed, SELL SIGNAL")", like sending an alert to mission control, and call "createOBJ()" to mark the pattern. We return 0, like reporting βno stormβ if the pattern isnβt found. For example, on a EURUSD H1 chart, if a candle opens at 1.2005, closes at 1.2000, with a high of 1.2006 and low of 1.1980 (candle size 26 pips), it qualifies (upper wick 1 pip < 2.6 pips, lower wick 20 pips > 18.2 pips), triggering a βSELL SIGNALβ alert. This is like spotting a flickering star at a resistance level, ready for your trading decision.
Step 3: Planting the BeaconβMarking the Hanging Man Pattern
Once weβve detected a Hanging Man, we mark it on the chart with a white arrow, like placing a beacon to signal a cosmic storm.
void createOBJ(datetime time, double price, int arrawcode, color clr){
string OBJName = " ";
if (ObjectCreate(0,OBJName,OBJ_ARROW,0,time,price)){
ObjectSetInteger(0,OBJName,OBJPROP_ARROWCODE,arrawcode);
ObjectSetInteger(0,OBJName,OBJPROP_COLOR,clr);
}
}Stepping into the visualization hub, the "createOBJ()" function is our tool for marking the pattern, like planting a glowing beacon on the chart. It creates a white arrow (code 233) at the candleβs low ("price") using "ObjectCreate(OBJ_ARROW)", setting its position with "time" and styling it with "ObjectSetInteger()" for the arrow code ("OBJPROP_ARROWCODE") and color ("OBJPROP_COLOR", white). However, thereβs a catch: the "OBJName" is set to a blank space (" "), which means all arrows overwrite each other at the same name, potentially causing issues (weβll address this in the notes).
Imagine this on GBPUSD: a Hanging Man forms at a high of 1.3505, low of 1.3475, open at 1.3503, and close at 1.3490. The EA places a white arrow at 1.3475, like a beacon flashing βSell alert!β at a resistance level. This visual cue makes it easy to spot the pattern, empowering you to decide whether to enter a sell trade or wait for confirmation, like a storm spotter assessing the sky before acting.
Step 4: Docking the StarshipβCleaning Up the Radar
As our mission nears its end, we prepare to dock the starship, ensuring the radar system shuts down cleanly.
void OnDeinit(const int reason){
}In the docking bay, the "OnDeinit()" function is our final stop, but itβs currently empty, like leaving the radarβs beacons glowing on the chart. This means the white arrows remain when you remove the EA, which could clutter your workspace. To tidy up, you could add "ObjectsDeleteAll()" to clear all arrows, like powering down your shipβs displays:
ObjectsDeleteAll(0, -1, -1);
ChartRedraw();For now, the empty "OnDeinit()" keeps things simple, like leaving your starship idling, but adding cleanup would ensure a pristine chart for your next mission. This lightweight approach lets you focus on spotting patterns without worrying about stray objects, setting the stage for future enhancements.
Why This EAβs a Cosmic Legend (and Keeps You Engaged!)
The Hanging Man EA is a cosmic legend, acting like a radar that spots bearish reversal patterns with precision, marking them with white arrows to guide your manual trades. Its simple design is perfect for beginners, while its potential for adding trading logic excites pros. Picture spotting a Hanging Man on EURUSD at 1.2000 after a rally, with a white arrow signaling a sell opportunity at a resistance levelβpure cosmic gold! The EAβs clear visuals and focused logic make it a must-have for traders hunting reversals, offering a foundation you can build on to conquer the forex galaxy.
Putting It All Together
To launch this EA:
Open MetaEditor in MetaTrader 5, like stepping onto your starshipβs bridge.
Copy the code, compile with F5, and check for errorsβno commander wants a faulty radar!
Drop the EA on your chart and watch for white arrows marking Hanging Man patterns, like beacons in the galaxy.
Use the signals to inform manual trades, pairing them with market analysis, like plotting a course through the stars.
Test on a demo account firstβreal pips deserve a practice mission!
Conclusion
Weβve crafted a Hanging Man Cosmic Spotter that lights up bearish reversals with white arrows, guiding your manual trading decisions with stellar precision. This MQL5 code is your cosmic radar, brought to life with a seamless, professional narrative that flows like a starry night, packed with clear explanations and vivid examples to spark your trading passion. Whether youβre just starting out or charting new galaxies, this EA empowers you to hunt market signals like a pro. Ready to explore further? Check our video guide on the website for a front-row seat to this cosmic mission. Now, go chase those bearish stars! π
Disclaimer: Trading is like spotting a cosmic stormβthrilling but risky. Losses can exceed deposits. Test strategies on a demo account before going live.