Back to Trending
RepositoryMQL5RORomania
Narfinsel

Narfinsel/Candlestick-Pattern-Scanner

CandlestickPatternScanner is a utility class that helps Expert Advisors and trading bots to efficiently detect reversal

122stars
49forks
1issues
4views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: expert-advisors

#1 Repository of the month

1
TINIX TRENDING·Topic: mql5-market

#1 Repository of the month

1
TINIX TRENDING·Topic: mql4

#1 Repository of the month

Candlestick-Pattern-Scanner

The Candlestick Pattern Scanner is a utility class that helps Expert Advisors and trading bots to efficiently detect reversal candle patterns. These special patterns can be used as potential indications of trend-reversals, especially in conjunction with other events, indicators and signals.

Detecting Reversal Candles

1. Intro

Motivation

Many online traders preffer to automate their trading strategies, but they don't have good, reliable scripts, to help confidently detect candle-stick pattern like stars, engulfings and consolidation. I struggled with this alot and decided to make things easier for myself and other traders, by programming in and sharing this MQL5 Metatrader script.

Problem

One of the biggest problems in trading with EAs (Expert Advisors/ trading bots) is finding reliable signals that can actually be used in code. There are many scripts in the marketplace that do visually idendify patterns on the chart, by drawing visual aids. But very few (if any) convert these candle-patterns into usable, code-ready objects, that can easily be incorporated as part of the internal making of an algorithm. Too many scripts only show patterns on the graphs, but that is useless for the trading bots, since they need objects from which to read data, to base decisions on.

Solution

My script identifies reversal patterns, it converts them into objects stored in an array. There is an option to customize how rigid the pattern-detection should be, to mark out only the strongest reversal signals. Visual square markings can be customized as well (color, style and thickness), for bullish and bearish patterns. I even optimized memory usage, by making sure to delete older patterns, or broken ones. Reversal patterns have many attributes and my code can read, change, and distinguish reversals based on their properties - to decide which trading actions to undertake.

2. Table of Contents

  1. Intro
  2. Table of Contents
  3. Project Description
  4. How to Install and Run the Project
  5. How to Tweak and Configure the Scanner Script Functionality
  6. How to Use the Project
  7. Credits
  8. License

3. Project Description

Green Red Bullish Bearish Reversals

Definition & Terminology

What are bearish reversal patterns? [RED] Bearish consolidations & engulfings, along with evening stars are price bar signals, indicating that the price will be going downwards. It will continue dropping or reverse & fall, after an uptrend.

What are bullish reversal patterns? [GREEN] Bullish patterns (consolidations, engulfings and morning stars) are a signal of rising prices. The price will be moving upwards, or reverse from downtrend to uptrend.

ReversalSTARS & HAMMERSENGULFINGSCONSOLIDATIONS
BEARISH
Evening Star

Bearish Engulfing

Bearish Consolidation
BULLISH
Morning Star

Bullish Engulfing

Bullish Consolidation

Based on priority, my scripts detects the following candle-patterns:

  • Consolidations are the strongest reversal signals since they hold the highest amount of trading information, spaning across 3 to 6 bars.
  • Engulfings represent highly trustworthy reversal patterns, particularly if their position & timing are right. They appear more frequently in mid-to-higher timeframes.
  • Stars & Hammers, are pretty reliable signals in high timeframes, if used togheter with other measurements and trading signals.
PriorityBULLISH Candle PatternsBEARISH Candle Patterns
1Bullish ConsolidationBearish Consolidation
2Bullish EngulfingBearish Engulfing
3Morning Star / HammerEvening Star

Candlestick Patterns Magenta and Gold

Bearish patterns are encircled in a magenta color, and they indicate a downward move in price. As shown in the graph above, this is actually true.

Bullish patterns appear in gold-yellow; bullish means that price will move upwards, and this appears to be the case here as well.

Candlestick Patterns Deep Pink and Aqua

Similar example, but since color is a completely customizable feature, I chose an alternative color scheme this time.

Deep pink means bearish signal. The price will drop, or reverse from uptrend to downtrend.

Aqua blue indicates a bullish reversal. Rising prices are expected, as the two bullish engulfings prove in this graphic.

Detecting Reversal Candles

Detecting Reversal Candles

4. How to Install and Run the Project

Step 1. Include the class file in your trading robot. The file-path (inside the "#include" preprocessor directive) might change depending on your folder structure or where you place the file:

#include <__SimonG\MS\CandlestickPatternScanner\CandlestickPatternScanner.mqh>

Step 2. Declare two global or local variables of type "CandlestickPatternScanner" and "CandlestickPattern". Note that "CandlestickPatternScanner" detects, stores and retrieves objects of type "CandlestickPattern", which are captured and saved at pointer location, as defined below:

CandlestickPatternScanner * cps;
CandlestickPattern * patternDetected;

Step 3. Initialize the CandlestickPatternScanner object. The best place for this is inside the OnInit() function.

int OnInit(){
   cps = new CandlestickPatternScanner (Symbol(), PERIOD_CURRENT, 15, true);
   cps.adjust_Settings_Graphic_BearishReversals (clrDeepPink, STYLE_SOLID, 4);
   cps.adjust_Settings_Graphic_BullishReversals (clrAqua, STYLE_SOLID, 4);
   cps.adjust_Settings_Chart_Subwindow (0, 0);
   cps.adjust_Settings_Engulfings (0.75, 5);
   cps.adjust_Settings_Stars (0.25, 40, 0.35);
   cps.setDoDrawCandlePatternRect (true);
}

Step 4. Activate the CandlestickPatternScanner (cps), and set it up so that it extracts the most recent price reversal pattern (captured at pointer variable CandlestickPattern (patternDetected)).

This function detects the most recent reversal and stores it inside an array of predefined-size (see previous step). Even though we write this piece of code inside OnTick(), because of the internal structure of CandlestickPatternScanner class, the function is only called every PERIOD_CURRENT minutes. (5min, 15min, ... 1 Day).

This periodicity can either be your current timeframe (PERIOD_CURRENT) or any other desired chart timeframe: PERIOD_M15, PERIOD_H4, PERIOD_D (check MQL5 specs).

void OnTick(){
   patternDetected = cps.updateAndReturn_Cps_onNewBar();
}

Step 5. Everything is set up. Use both objects and the most recently detected reversal pattern (bullish / bearish) in your code logic for the algorithm, to determine trading outcome.

bool validateOpenBuy (){
   if(patternDetected != NULL){
         if(patternDetected.getPatternType() == BULLISH_ENGULFING)
            return true;
      else if(patternDetected.getPatternType() == BULLISH_MORNING_STAR)
            return true;
   }
   return false;
}

bool validateOpenSell (){
   if(patternDetected != NULL){
         if(patternDetected.getPatternType() == BEARISH_ENGULFING)
            return true;
      else if(patternDetected.getPatternType() == BEARISH_EVENING_STAR)
            return true;
   }
   return false;
}

Step 6. Memory clean-up, optimization, object deletion. Clean-up is by default automatically performed by the CandlestickPatternScanner in two ways:

Patterns in the internal storage-array are deleted once broken. Secondly, since the array has a LIFO structure (Last-In-First-Out), whenever a new object is detected and stored, the last one (oldest one) is popped out and deleted. Closing/stopping the EA-bot eliminates the CandlestickPatternScanner objects, which removes the array and the CandlestickPattern objects inside of it:

void OnDeinit (const int reason){
   delete cps;
   delete patternDetected;
}

5. How to Tweak and Configure the Scanner Script Functionality

This is how you can configure your scripts.

6. How to Use the Project

Now that we know how to install and run the project, let's see how we can use it. I shall provide a bunch of ideas for trading robots:

PatternMoving AverageTrading Outcome
Bullish PatternPrice above MA50Open BUY trade.
Bearish PatternPrice below MA50Open SELL trade.
PatternRSITrading Outcome
Bullish PatternOverbought (RSI<30)Open BUY trade.
Bearish PatternOversold (RSI>30)Open SELL trade.
PatternBollinger BandsTrading Outcome
Bullish PatternPrice above Upper BandOpen BUY trade.
Bearish PatternPrice below Lower BandOpen SELL trade.
PatternIchimoku CloudTrading Outcome
Bullish PatternGreen Cloud (Leading A)Open BUY trade.
Bearish PatternRed Cloud (Leading B)Open SELL trade.
PatternPriceMACDTrading Outcome
Bullish Engulfing on D/W/MoReach engulf. conterminous lineValue above Signal on H1/H4.Open BUY trade.
Bearish Engulfing on D/W/MoReach engulf. conterminous lineSignal above Value on H1/H4.Open SELL trade.
PatternPriceMACDTrading Outcome
Bullish Engulfing on D/W/MoReach engulf. conterminous lineValue is negative and below a threshold.Open BUY trade.
Bearish Engulfing on D/W/MoReach engulf. conterminous lineValue is posative and above a threshold.Open SELL trade.

7. Credits

I can't credit anyone directly, but this section seems appropriate because I owe special thanks to so many course & content creators, chanels, youtubers.

1. MQL4 Programming. Visit https://www.youtube.com/channel/UCIuhfiM34b2P8qv_HX_uwug/featured

2. ForexBoat Team. Check out https://www.udemy.com/course/learn-mql4/

These guys create amazing content and I have learned so much from them!

8. License

Feel free to use this project for yourself. Or to edit it, use bits of it. Do not commercialize it! My Candlestick-Pattern-Scanner project is licensed under the GNU AGPLv3 license. Check out the licence link to better understand what you can and cannot do with this code.

Similar Projects

Discover other similar projects and AI models.

RepositoryHTML
matthewkastor/Metatrader

Expert advisors, scripts, indicators and code libraries for Metatrader.

165
Mar 2, 2023
RepositoryHTML
AbdulWasay13/TradingView-Pipe-Executor

Automated MT5 Trading Bot with AI Alerts & Webhook Bridge 2026

132
Nov 14, 2026
RepositoryHTML
Dream-XR/MT5-Post-Trade-Insight-Reporter

AutoTrade Forex Signals: Telegram to MT5 EA 2026 Strategy

121
Nov 27, 2026
RepositoryHTML
bipbopcompany-droid/Risk-Nexus-Command

Prop Matrix Engine 2026: Multi-Account MT5 Risk Control with Global Drawdown Guard & Kill-Switch

117
Nov 22, 2026
RepositoryMQL5
EarnForex/MarketProfile

Market Profile indicator for MT4, MT5, and cTrader by EarnForex.com

205
Mar 13, 2026
RepositoryMQL5
EarnForex/Account-Protector

Automate emergency position closing and autotrading termination using a multi-setting expert advisor.

126
Feb 19, 2026
RepositoryMQL5
6alaile/MetaTrader5-to-Telegram

An expert advisor to help traders connect their MT5 account, via the terminal with a Telegram Bot to broadcast messages to a user, group or channel.

110
Sep 29, 2021
RepositoryMQL5
EarnForex/News-Trader

News Trader is a customizable expert advisor to trade high-volatility news releases based on the trader's inputs.

59
Aug 8, 2025
RepositoryMQL5
EarnForex/AutoTrading-Scheduler

Create simple weekly schedule for your autotrading needs in MT4 and MT5.

57
Mar 2, 2026