Prism Candle Forge
- Libraries
-
Syarief Azman Bin Rosli
Hello and welcome to my official MQL5 profile!
I am Syarief Azman Bin Rosli, an algorithmic trading systems developer and quantitative software engineer with over a decade of specialized experience creating robust automated trading solutions for MetaTrader 5 and MetaTrader 4. - Version: 1.0
- Activations: 5
Prism Candle Forge — Candlestick Pattern Recognition Engine for MT4
Prism Candle Forge is a native MQL4 library that detects and validates 20+ Japanese candlestick patterns using ATR-weighted geometric analysis. It provides pattern identification, directional confidence scoring, candle morphology classification, and trend context validation — all through 8 exported functions callable from any Expert Advisor, Indicator, or Script. Zero DLLs, zero external dependencies, pure MQL4 computation.
Distributed as a compiled binary (Prism_Candle_Forge.ex4). This description is your complete API reference.
Installation
- Download Prism_Candle_Forge.ex4 from MQL5 Market.
- Place it in: MQL4/Libraries/
- Add the #import block below into your .mq4 source file.
- Compile your EA or Indicator. All 8 functions are now available.
Import Declaration (Copy-Paste Ready)
#import "Prism_Candle_Forge.ex4" int PCF_DetectPattern(const double &open[], const double &high[], const double &low[], const double &close[], int bar_index, double atr_value, string &pattern_name, double &confidence, int &direction); int PCF_ScanMultiPattern(const double &open[], const double &high[], const double &low[], const double &close[], int bar_index, double atr_value, string &pattern_names[], double &confidences[], int &directions[], int max_patterns); double PCF_PatternStrength(const double &open[], const double &high[], const double &low[], const double &close[], int bar_index, double atr_value); int PCF_CandleType(double open_price, double high_price, double low_price, double close_price, double atr_value); double PCF_BodyRatio(double open_price, double high_price, double low_price, double close_price); double PCF_WickBalance(double open_price, double high_price, double low_price, double close_price); int PCF_IsTrendConfirmed(const double &close[], int bar_index, int lookback_period, double min_slope_pips); int PCF_GetVersion(); #import
API Reference
PCF_DetectPattern
Detects the strongest candlestick pattern at a specific bar. Recognizes 20+ patterns including Hammer, Engulfing, Morning/Evening Star, Doji variants, Piercing Line, Dark Cloud Cover, Three White Soldiers, Three Black Crows, Harami, Tweezer, Marubozu, Hanging Man, and Shooting Star.
Parameters:
- open[], high[], low[], close[]: OHLC price arrays from the chart.
- bar_index: Index of the bar to analyze. Must be valid within array bounds.
- atr_value: Current ATR value for adaptive threshold scaling. Must be positive.
- pattern_name (by ref): Receives the name of the strongest detected pattern (e.g. "Bullish Engulfing").
- confidence (by ref): Pattern confidence score from 0.0 (weak) to 1.0 (textbook perfect).
- direction (by ref): +1 for bullish, -1 for bearish signal.
Returns: Number of patterns detected at this bar (0 if none). Sets output parameters to the strongest pattern by confidence.
PCF_ScanMultiPattern
Scans for ALL candlestick patterns at a single bar and returns multiple results sorted by confidence descending.
Parameters:
- open[], high[], low[], close[]: OHLC price arrays.
- bar_index: Bar to analyze.
- atr_value: ATR for adaptive thresholds.
- pattern_names[] (by ref): Array receiving pattern names. Resized internally up to max_patterns.
- confidences[] (by ref): Array receiving confidence scores.
- directions[] (by ref): Array receiving directions (+1/-1).
- max_patterns: Maximum number of results to return (e.g. 5).
Returns: Actual number of patterns found (0 to max_patterns).
PCF_PatternStrength
Returns an aggregate directional pressure score combining all detected patterns at a bar.
Parameters:
- open[], high[], low[], close[]: OHLC arrays.
- bar_index: Target bar index.
- atr_value: ATR for scaling.
Returns: Score from -100.0 (extreme bearish) to +100.0 (extreme bullish). Zero means neutral.
PCF_CandleType
Classifies a single candle into one of 8 morphological types using ATR-relative body and wick proportions.
Parameters:
- open_price, high_price, low_price, close_price: Single candle OHLC values.
- atr_value: ATR for relative sizing. If zero or negative, uses absolute thresholds.
Returns: 1=Bull Marubozu, 2=Bear Marubozu, 3=Hammer, 4=Inverted Hammer, 5=Doji, 6=Spinning Top, 7=Standard Bull, 8=Standard Bear.
PCF_BodyRatio
Calculates the body-to-range ratio of a candle. Useful for filtering candle significance.
Parameters:
- open_price, high_price, low_price, close_price: Single candle OHLC.
Returns: Ratio from 0.0 (no body / doji) to 1.0 (full body / marubozu). Returns 0.0 if range is zero.
PCF_WickBalance
Measures the directional wick asymmetry of a candle.
Parameters:
- open_price, high_price, low_price, close_price: Single candle OHLC.
Returns: -1.0 (all lower wick, bullish rejection) to +1.0 (all upper wick, bearish rejection). 0.0 means symmetrical wicks. Returns 0.0 if total wick length is zero.
PCF_IsTrendConfirmed
Validates trend context using linear regression slope over a lookback window. Use to filter patterns that align with the prevailing trend.
Parameters:
- close[]: Close price array.
- bar_index: Starting bar for the lookback window.
- lookback_period: Number of bars to evaluate. Minimum 5. Clamped to array bounds.
- min_slope_pips: Minimum absolute slope (in pips) to qualify as a trend.
Returns: +1 (uptrend confirmed), -1 (downtrend confirmed), 0 (ranging/flat or insufficient data).
PCF_GetVersion
Returns the library version as an integer for runtime compatibility checks.
Returns: 100 (representing version 1.00).
Working Integration Example
#property strict #import "Prism_Candle_Forge.ex4" int PCF_DetectPattern(const double &open[], const double &high[], const double &low[], const double &close[], int bar_index, double atr_value, string &pattern_name, double &confidence, int &direction); double PCF_PatternStrength(const double &open[], const double &high[], const double &low[], const double &close[], int bar_index, double atr_value); int PCF_CandleType(double open_price, double high_price, double low_price, double close_price, double atr_value); int PCF_GetVersion(); #import void OnTick() { double o[], h[], l[], c[]; ArrayCopyRates(o, Symbol(), 0); int copied = CopyOpen(Symbol(), 0, 0, 100, o); CopyHigh(Symbol(), 0, 0, 100, h); CopyLow(Symbol(), 0, 0, 100, l); CopyClose(Symbol(), 0, 0, 100, c); double atr = iATR(Symbol(), 0, 14, 1); string pat_name; double conf; int dir; int count = PCF_DetectPattern(o, h, l, c, 1, atr, pat_name, conf, dir); if(count > 0) Print("Pattern: ", pat_name, " Confidence: ", conf, " Direction: ", dir); double strength = PCF_PatternStrength(o, h, l, c, 1, atr); Print("Aggregate Strength: ", strength); int candle = PCF_CandleType(o[1], h[1], l[1], c[1], atr); Print("Candle Type: ", candle); }
Architecture
All 8 functions are stateless and independent. Each call performs pure geometric and statistical analysis on the provided OHLC arrays with no persistent state, no chart objects, no timers, and no network access. ATR-relative thresholds ensure correct pattern detection across all instruments (forex, metals, indices, crypto) and all timeframes without parameter adjustment.
Compatibility
- Platform: MetaTrader 4 only
- Strategy Tester: Fully compatible (backtesting and optimization)
- External Dependencies: None (zero DLLs)
- No chart objects, no timers, no visual output — pure computation engine
- Thread Safety: All functions are stateless; safe for multi-chart deployment
