Introduction
Greetings, forex storm spotters! Picture the forex market as a vast galaxy, with prices soaring like stars before a dramatic fall. The Evening Star EA is your cosmic radar system, an MQL5 bot that detects the Evening Star candlestick patternβa three-candle formation signaling a bearish reversal after an uptrend. It marks these patterns with red arrows on the chart, like flagging a falling star, 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 meteor shower, and examplesβlike spotting Evening Star on EURUSDβto keep you engaged. Weβll quote variables (e.g., "open1") and functions (e.g., "OnInit()") for clarity, balancing pro insights with a sprinkle of charm. Ready to track those cosmic reversals? Letβs launch this Evening Star spotter!
Strategy Blueprint
The Evening Star EA automates pattern detection:
Pattern Detection: Identifies a three-candle Evening Star: a bullish first candle (open below close), a small-bodied second candle (body less than 50% of the first and third), and a bearish third candle (open above close) closing below the second candleβs midpoint.
Visualization: Marks the pattern with a red arrow at the third candleβs high on the chart.
Purpose: Highlights bearish reversal points for manual trading decisions, not executing trades, like a radar guiding a storm chaserβs strategy.
Features: Uses a 0.5 bar ratio for the second candleβs size, with a simple, lightweight design. Itβs like a cosmic radar, pinpointing Evening Star patterns to guide traders through market turning points with precision.

Code Implementation
Letβs navigate the MQL5 code like storm spotters tracking a cosmic tempest, building our Evening Star 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 starry night. 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 Cosmic RadarβPreparing the EA
We start by rigging our radar station, defining the EAβs structure to spot Evening Star patterns.
//+------------------------------------------------------------------+
//| EVENING STAR.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, updated to your preferred metadata for 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 Evening Star detection, like a spotter gearing up for a cosmic chase.
Step 2: Scanning for Cosmic StormsβDetecting the Evening Star Pattern
With the radar set, we scan for the Evening Star pattern, like spotting a falling star in the galaxy.
int getEveningStar(double bar_ratio){
datetime time = iTime(_Symbol,PERIOD_CURRENT,1);
double open1 = iOpen(_Symbol,PERIOD_CURRENT,1);
double high1 = iHigh(_Symbol,PERIOD_CURRENT,1);
double low1 = iLow(_Symbol,PERIOD_CURRENT,1);
double close1 = iClose(_Symbol,PERIOD_CURRENT,1);
double open2 = iOpen(_Symbol,PERIOD_CURRENT,2);
double high2 = iHigh(_Symbol,PERIOD_CURRENT,2);
double low2 = iLow(_Symbol,PERIOD_CURRENT,2);
double close2 = iClose(_Symbol,PERIOD_CURRENT,2);
double open3 = iOpen(_Symbol,PERIOD_CURRENT,3);
double high3 = iHigh(_Symbol,PERIOD_CURRENT,3);
double low3 = iLow(_Symbol,PERIOD_CURRENT,3);
double close3 = iClose(_Symbol,PERIOD_CURRENT,3);
double barsize1 = high1-low1;
double barsize2 = high2-low2;
double barsize3 = high3-low3;
if (open1 > close1){
if (open3 < close3){
if (barsize2 < barsize1*bar_ratio && barsize2 < barsize3*bar_ratio){
Print("We found the EVENING STAR");
createARRAW(time,high1);
return -1;
}
}
}
return 0;
}
void OnTick(){
getEveningStar(0.5);
}In "OnTick()", we call "getEveningStar(0.5)" to check for the pattern on every tick, though a new-bar check would optimize performance (see notes). In "getEveningStar()", we grab data for the latest three candles (bars 1, 2, 3) using "iTime()", "iOpen()", "iHigh()", "iLow()", "iClose()". We calculate bar sizes ("barsize1", "barsize2", "barsize3") as high minus low. The Evening Star requires: a bullish third candle ("open3 < close3"), a small-bodied second candle ("barsize2 < barsize1*bar_ratio", "barsize2 < barsize3*bar_ratio", with bar_ratio=0.5), and a bearish first candle ("open1 > close1"). If valid, we log with "Print()", (βWe found the EVENING STARβ), call "createARRAW()", and return -1, like flagging a pattern on EURUSD at 1.2000. Otherwise, we return 0, like reporting clear skies.
Step 3: Flagging the StormβMarking the Evening Star Pattern
Pattern spotted? We mark it with a red arrow, like planting a warning flag for a cosmic storm.
void createARRAW (datetime time, double price){
string name = "EVENING STAR";
if (ObjectCreate(0,name,OBJ_ARROW,0,time,price)){
ObjectSetInteger(0,name,OBJPROP_ARROWCODE,234);
ObjectSetInteger(0,name,OBJPROP_COLOR,clrRed);
ObjectSetInteger(0,name,OBJPROP_WIDTH,5);
}
}In "createARRAW()", we create a red arrow (code 234, 5-pixel width) at the bearish candleβs high using "ObjectCreate(OBJ_ARROW)", "ObjectSetInteger()", named "EVENING STAR". This marks the pattern, like a neon flag on GBPUSDβs chart at 1.3500βs high, signaling a bearish reversal for traders to assess, though the fixed name may cause issues (see notes).
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 "EVENING STAR" arrows, like packing up gear, but for now, itβs a light cleanup, ready for the next storm.

Why This EAβs a Cosmic Legend (and Keeps You Engaged!)
This EA is a reversal-spotting legend, detecting Evening Star patterns like a radar tracking falling stars, 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 an Evening Star on EURUSD at 1.2000 after an uptrend, signaling a sell at resistance, or on GBPUSD for a high-probability reversalβpure cosmic 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 cosmic radar.
Paste the code, compile (F5), and check for typosβno spotter wants a faulty dish.
Drop the EA on your chart and watch for red arrows marking Evening Star patterns.
Use the signals to inform manual trades, like chasing a cosmic stormβs path.
Test on a demo firstβreal pips deserve a practice chase!
Conclusion
Weβve crafted an Evening Star cosmic spotter that detects bearish reversals with red arrows, guiding manual trading decisions with precision. This MQL5 code is our stellar 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 starry night. Ready to track? Check our video guide on the website for a front-row seat to this cosmic reversal mission. Now go hunt those market stars! π
Disclaimer: Tradingβs like spotting a cosmic stormβthrilling but risky. Losses can exceed deposits. Test strategies on a demo account before going live.