Viewing the resource: Shooting Star Pattern Detector in MQL5

Shooting Star Pattern Detector in MQL5

Allan Munene Mutiiria 2025-06-26 01:02:12 78 Views
This MQL5 EA detects the shooting star candlestick pattern, marking bearish reversals with a white a...

Introduction

Picture spotting bearish reversals with the precision of a master chart analyst, using a classic candlestick pattern to highlight potential market downturns. The Shooting Star EA is your advanced pattern spotting tool, designed to identify the shooting star candlestick—a bearish reversal pattern characterized by a small body near the candle’s low (lower wick less than 7% of the range, "close - low < candlesize * 0.07"), a long upper wick (at least 70% of the range, "high - open > candlesize * 0.7"), and a bearish close ("open > close")—via the "getShootingStar()" function. When detected, a white arrow ("createArrow()", "OBJ_ARROW", code 222) is placed above the candle’s high, serving as a visual alert for traders to evaluate bearish opportunities, such as sell trades or position closures. No automated trades are executed, leaving action to the trader’s discretion. This non-trading EA suits traders enhancing chart analysis in trending or volatile markets, requiring risk management to validate signals with additional context.

This article is crafted with a professional, engaging, and seamless narrative, flowing like a well-calibrated pattern spotting system, designed to inform and captivate readers. Tailored for both novice and experienced traders, we’ll dissect each code component with clear, precise explanations, as if guiding an apprentice analyst through a pattern-detection project. With vivid examples—like spotting patterns on EURUSD—and a polished tone, we’ll explore how the EA initializes, detects patterns, marks signals, and ensures cleanup. Using a precision pattern spotting metaphor, this guide will illuminate the code’s technical rigor, empowering you to identify reversals with confidence. Let’s activate the system and begin this pattern-spotting expedition!

Strategy Blueprint

Let’s outline the EA’s pattern spotting framework, like drafting specifications for a chart analysis radar:

  • Pattern Detection: Identifies a shooting star when a bearish candle forms with a small body near the low (lower wick <7% of range), a long upper wick (>70% of range), and a bearish close, using "getShootingStar()", "iOpen()", "iHigh()", "iLow()", "iClose()".

  • Visual Marking: Places a white arrow above the candle’s high ("createArrow()", "OBJ_ARROW") to alert traders of a bearish reversal signal.

  • Trader Action: Relies on traders to act on marked patterns, with no automated trading logic.

  • Execution: Processes patterns on each tick ("OnTick()") with data from "iTime()".

  • Enhancements: Adding automated sell trades, signal filters (e.g., trend context), or cleanup logic could improve functionality. This framework enhances chart analysis with precision, marking shooting stars for trader awareness.

Code Implementation

Let’s step into the pattern spotting control room and dissect the MQL5 code that powers this Shooting Star EA. We’ll guide you through each phase like expert analysts, ensuring the narrative flows seamlessly with professional clarity and engaging precision that captivates readers. We’ll cover initialization, pattern detection, visual marking, and cleanup, with detailed explanations and examples—like spotting patterns on EURUSD—to make it accessible for beginners. Each phase will build on the last, crafting a cohesive technical narrative that transforms code into a compelling pattern-detection project. Let’s power up the system and begin!

Phase 1: Constructing the Framework—Initialization

We start by building the detection system, initializing the EA for pattern analysis.

//+------------------------------------------------------------------+
//|                                               shooting start.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."
                      "Hope you will enjoy the EA Logic.\n"
#property description "*** HAPPY TRADING! ***"
#property version   "1.00"

int OnInit(){
   return(INIT_SUCCEEDED);
}

The system begins with the #property header, establishing copyright, a YouTube link, and descriptive metadata, like calibrating a pattern spotting radar’s core. The "OnInit()" function initializes the setup with minimal configuration, as no indicators or trading objects are required (no "Trade/Trade.mqh" inclusion). Returning INIT_SUCCEEDED signals, “System is ready, let’s spot patterns!” This minimal setup primes the EA for candlestick-based detection, like a radar poised for action. Note: The EA is described as free, with source code available via the provided YouTube link, enhancing accessibility.

Phase 2: Mapping Patterns—Detecting the Shooting Star

With the system active, we analyze candlestick data to detect the shooting star pattern, like scanning charts for reversal signals.

int getShootingStar(){
   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 (close - low < candlesize * 0.07){
         if (high - open > candlesize * 0.7){
            Print("SHOOTING STAR FORMED");
            createArrow(time,high,222,clrWhite);
         }
      }
   }
   return 0;
}

In the pattern mapping hub, "getShootingStar()" fetches data for the most recent closed candle (bar 1) using "iTime()", "iOpen()", "iHigh()", "iLow()", "iClose()". It calculates the candle’s range ("candlesize", "high - low") and checks three conditions: (1) bearish candle ("open > close"), (2) small lower wick ("close - low < candlesize * 0.07", <7% of range), and (3) long upper wick ("high - open > candlesize * 0.7", >70% of range). If met, it logs with "Print()" (“SHOOTING STAR FORMED”) and calls "createArrow()" to mark the pattern, returning 0 regardless of detection. For example, on EURUSD H1, a candle with open=1.2010, high=1.2020, low=1.1990, close=1.1992 (range=0.0030, lower wick=0.0002<0.00021, upper wick=0.0010>0.0021) triggers a signal, like spotting a bearish reversal.

Phase 3: Marking Signals—Visualizing Patterns

With patterns detected, we mark the shooting star visually, like highlighting signals on a chart.

void createArrow(datetime time, double price, int code, color clr){
   string name = " ";
   if (ObjectCreate(0,name,OBJ_ARROW,0,time,price)){
      ObjectSetInteger(0,name,OBJPROP_ARROWCODE,code);
      ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
   }
}

In the signal marking hub, "createArrow()" attempts to place a white arrow ("OBJ_ARROW", "code"=222, "clrWhite") at the candle’s high ("price", "time") using "ObjectCreate()". It sets arrow properties ("ObjectSetInteger()", "OBJPROP_ARROWCODE", "OBJPROP_COLOR") but uses an empty string ("name = " ") for the object name, which may cause issues (see notes). For example, on EURUSD H1, an arrow appears above 1.2020 for a shooting star, like annotating a chart for trader awareness.

Phase 4: Shutting Down the System—Cleaning Up Resources

As our expedition concludes, we shut down the system, ensuring resources are cleared.

void OnDeinit(const int reason){
}

In the shutdown control room, "OnDeinit()" is empty, leaving arrows ("OBJ_ARROW") on the chart, like an active spotting system. Adding cleanup would ensure a clean slate:

ObjectsDeleteAll(0, -1, -1);

This would remove all objects with "ObjectsDeleteAll()", like dismantling a pattern spotting radar, ready for the next task.

Why This EA is a Pattern Spotting Triumph

The Shooting Star EA is a pattern detection triumph, identifying bearish reversals with precision, like a master-crafted spotting radar. Its rigorous candlestick logic ("getShootingStar()", "candlesize") and visual markers ("createArrow()") enhance trader awareness, with potential for automated trading or cleanup logic. Picture a white arrow on EURUSD at 1.2020 signaling a shooting star—strategic brilliance! Beginners will value the clear visuals, while experts can enhance its framework, making it essential for traders leveraging pattern recognition.

Putting It All Together

To deploy this EA:

  1. Open MetaEditor in MetaTrader 5, like entering your pattern spotting control room.

  2. Copy the code, compile with F5, and verify no errors—no analyst wants a faulty radar!

  3. Attach the EA to your chart and watch it mark shooting star patterns with white arrows.

  4. Monitor logs (e.g., “SHOOTING STAR FORMED”) for pattern tracking, like spotting diagnostics.

  5. Test on a demo account first—real trading decisions require a trial run!

Conclusion

We’ve engineered a Shooting Star Detector that identifies bearish reversals with precision, like a master-crafted pattern spotting system. This MQL5 code is your strategic tool, brought to life with a seamless, professional narrative packed with clear explanations and vivid examples to fuel your trading insight. Whether you’re a novice chart analyst or a seasoned market strategist, this EA empowers you to spot reversals with confidence. Ready to detect? Watch our video guide on your YouTube channel (linked in the code) for a step-by-step creation process. Now, illuminate your trading charts with precision! 🔍

Disclaimer: Trading is like navigating complex markets—challenging and 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!