Viewing the resource: Crafting an Evening Star Cosmic Spotter with MQL5 🌠

Crafting an Evening Star Cosmic Spotter with MQL5 🌠

Allan Munene Mutiiria 2025-06-21 18:05:04 100 Views
Join us for a detailed, professional, and engaging journey through our MQL5 code that automates Even...

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:

  1. Open MetaEditor in MetaTrader 5 like setting up a cosmic radar.

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

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

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

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

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!