### Clean Chart Objects (MQL5) Source: https://context7.com/haza79/mt5-smart-money-concept-indicator/llms.txt This MQL5 script removes all graphical objects and text comments from the current MetaTrader 5 chart. It's useful for starting fresh before applying new indicators or EAs to prevent interference from existing drawings. It executes once when run. ```mql5 // File: Clean up all drawings ( Delete All Object Comment etc ).mq5 // This script runs once when executed void OnStart() { // Delete all objects on current chart (0 = current chart) ObjectsDeleteAll(0); // Clear comment text from chart Comment(""); Print("Chart cleaned: All objects and comments removed"); } ``` -------------------------------- ### MQL5 Indicator Initialization and Calculation Loop Source: https://context7.com/haza79/mt5-smart-money-concept-indicator/llms.txt This MQL5 code sets up an MT5 indicator by defining chart properties, buffer counts, and plot counts. It includes necessary header files for various SMC components, instantiates class objects, initializes indicator buffers, and configures each component in a specific dependency order within the OnInit() function. The OnCalculate() function then processes price data incrementally, updating MACD and other components for recent bars to detect market structure elements and plot indicators. ```mql5 #property indicator_chart_window #property indicator_buffers 16 #property indicator_plots 16 // Include all required modules #include "BarData.mqh" #include "InsideBarClass.mqh" #include "ImpulsePullbackDetector.mqh" #include "Fractal.mqh" #include "MACD.mqh" #include "MACDFractal.mqh" #include "MacdMarketStructure.mqh" #include "Fibonacci.mqh" #include "PlotFiboOnChart.mqh" #include "OrderBlock.mqh" // Declare class instances MACD macd; BarData barData; MACDFractalClass macdFractal; MacdMarketStructureClass macdMarketStructure; InsideBarClass insideBar; ImpulsePullbackDetectorClass impulsePullbackDetector; FractalClass fractal; Fibonacci fibonacci; PlotFiboOnChart plotFiboOnChart; OrderBlock orderBlock; int OnInit() { // Configure indicator buffers for visualization SetIndexBuffer(0, macdFractal.macdHighFractalBuffer, INDICATOR_DATA); SetIndexBuffer(1, macdFractal.macdLowFractalBuffer, INDICATOR_DATA); SetIndexBuffer(2, macdMarketStructure.majorSwingHighBuffer, INDICATOR_DATA); SetIndexBuffer(3, macdMarketStructure.majorSwingLowBuffer, INDICATOR_DATA); SetIndexBuffer(4, macdMarketStructure.bullishBosDrawing.buffer, INDICATOR_DATA); SetIndexBuffer(5, macdMarketStructure.bullishChochDrawing.buffer, INDICATOR_DATA); SetIndexBuffer(6, macdMarketStructure.bearishBosDrawing.buffer, INDICATOR_DATA); SetIndexBuffer(7, macdMarketStructure.bearishChochDrawing.buffer, INDICATOR_DATA); SetIndexBuffer(8, macdMarketStructure.inducementDrawing.buffer, INDICATOR_DATA); // Initialize all components in dependency order insideBar.Init(); impulsePullbackDetector.Init(&insideBar); fractal.Init(&impulsePullbackDetector); macdFractal.Init(&macd, &barData); macdMarketStructure.init(&macdFractal, &barData, &fractal); fibonacci.init(&barData, &macdMarketStructure); plotFiboOnChart.init(&fibonacci, &barData); orderBlock.Init(&barData, &macdMarketStructure, &fractal, &insideBar, &fibonacci); return(INIT_SUCCEEDED); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { // Set bar data once per calculation if (!barData.SetData(rates_total, time, open, high, low, close)) { Print("Setting data failed"); return rates_total; } // Calculate start position (incremental updates) int start = prev_calculated == 0 ? 0 : prev_calculated - 1; // Process each closed bar for (int i = start; i < rates_total; i++) { // Update MACD indicator macd.update(close[i], i, rates_total); // Process only recent 1618 bars for performance if (i > rates_total - 1618) { insideBar.Calculate(i, rates_total, high, low); impulsePullbackDetector.Calculate(i, rates_total, high, low); macdFractal.Update(i); fractal.Calculate(i, high, low, rates_total); macdMarketStructure.update(i, rates_total); fibonacci.update(i, rates_total); plotFiboOnChart.update(i, rates_total); orderBlock.update(i, rates_total); } } return rates_total; } ``` -------------------------------- ### MQL5: Detect Order Blocks Source: https://context7.com/haza79/mt5-smart-money-concept-indicator/llms.txt Identifies institutional order blocks by detecting fractal sweeps combined with Fair Value Gaps (FVG). It requires initialization of OrderBlock, BarData, MacdMarketStructureClass, FractalClass, InsideBarClass, and Fibonacci objects. The detection process involves identifying swept fractals, Fair Value Gaps, and untaken order blocks. ```mql5 // Initialize order block detector OrderBlock orderBlock; BarData barData; MacdMarketStructureClass macdMarketStructure; FractalClass fractal; InsideBarClass insideBar; Fibonacci fibonacci; orderBlock.Init(&barData, &macdMarketStructure, &fractal, &insideBar, &fibonacci); // Detect order blocks for (int i = start; i < rates_total; i++) { macdMarketStructure.update(i, rates_total); fractal.Calculate(i, high, low, rates_total); fibonacci.update(i, rates_total); orderBlock.update(i, rates_total); // Order blocks are calculated when inducement is broken // The system identifies: // 1. Fractals swept by wicks (stop hunts) // 2. Fair Value Gaps (3-candle imbalance patterns) // 3. Untaken order blocks (not yet retested) // Order block details are printed to Expert log // with timestamps for manual review } // Example: Bullish order block formation // 1. Market creates major low // 2. Fractals form above major low // 3. Price sweeps fractals with wicks (liquidity grab) // 4. Fair Value Gap forms after sweep // 5. Order block validated if not yet retested ``` -------------------------------- ### Recognize Fractal Patterns (MQL5) Source: https://context7.com/haza79/mt5-smart-money-concept-indicator/llms.txt Validates swing points as fractals by checking their surrounding price action. This MQL5 snippet initializes the FractalClass, processes fractal data, and demonstrates how to retrieve fractals within a specified range. ```mql5 // Initialize fractal detector FractalClass fractal; ImpulsePullbackDetectorClass impulsePullbackDetector; impulsePullbackDetector.Init(&insideBar); // Assuming insideBar is initialized elsewhere fractal.Init(&impulsePullbackDetector); // Process fractals for (int i = start; i < rates_total; i++) { impulsePullbackDetector.Calculate(i, rates_total, high, low); // Assuming impulsePullbackDetector is initialized elsewhere fractal.Calculate(i, high, low, rates_total); // Access fractal data if (fractal.latestFractalHighIndex != -1) { Print("High Fractal: ", fractal.latestFractalHighPrice, " at bar ", fractal.latestFractalHighIndex); } // Get fractals within a range int fractalsInRange[]; fractal.GetFractalFromRange(100, 200, true, fractalsInRange); for (int j = 0; j < ArraySize(fractalsInRange); j++) { int fractalIndex = fractalsInRange[j]; Print("Fractal found at bar: ", fractalIndex); } } ``` -------------------------------- ### MQL5: Calculate Fibonacci Levels Source: https://context7.com/haza79/mt5-smart-money-concept-indicator/llms.txt Calculates Fibonacci retracement, circle, and timezone levels based on major market structure. It requires initialization of Fibonacci, MacdMarketStructureClass, and BarData objects. The output includes specific retracement levels (50%, 61.8%, 78.6%, 88.7%) and the current trend context. ```mql5 // Initialize Fibonacci calculator Fibonacci fibonacci; MacdMarketStructureClass macdMarketStructure; BarData barData; fibonacci.init(&barData, &macdMarketStructure); // Process Fibonacci levels for (int i = start; i < rates_total; i++) { macdMarketStructure.update(i, rates_total); fibonacci.update(i, rates_total); // Check if Fibonacci retracement is calculated if (fibonacci.isFiboRetraceCalculated) { // Get specific retracement levels double fibo50 = fibonacci.fiboRetrace.getFiboLevel(0); // 50% double fibo618 = fibonacci.fiboRetrace.getFiboLevel(1); // 61.8% double fibo786 = fibonacci.fiboRetrace.getFiboLevel(2); // 78.6% double fibo887 = fibonacci.fiboRetrace.getFiboLevel(3); // 88.7% Print("Fibo Levels - 50%: ", fibo50, " | 61.8%: ", fibo618, " | 78.6%: ", fibo786, " | 88.7%: ", fibo887); // Check current trend for context Trend trend = fibonacci.trend; if (trend == TREND_BULLISH) { Print("Looking for long entries at retracement levels"); } } // Fibonacci circle and timezone if (fibonacci.isFiboCircleCalculated) { Print("Fibonacci circle levels calculated"); } } ``` -------------------------------- ### Python: Generate Candlesticks from Swings Source: https://context7.com/haza79/mt5-smart-money-concept-indicator/llms.txt Generates realistic OHLC candlestick data from swing points for backtesting and visualization. This utility is implemented in Python and utilizes pandas for data manipulation and a custom function `generate_candlesticks_from_swings` for creating the data. ```python import pandas as pd from generate_candle import generate_candlesticks_from_swings, plot_candlestick ``` -------------------------------- ### Custom MACD Calculation and Trend Analysis (MQL5) Source: https://context7.com/haza79/mt5-smart-money-concept-indicator/llms.txt Provides a real-time MACD calculation using exponential moving averages for trend identification. This MQL5 implementation initializes the MACD indicator, updates it with price data, and checks for crossovers. ```mql5 // Initialize MACD with custom periods MACD macd(12, 26, 9); // Fast=12, Slow=26, Signal=9 // Update on each closed bar for (int i = start; i < rates_total; i++) { macd.update(close[i], i, rates_total); // Access current values double macdLine = macd.getMACD(); double signalLine = macd.getSignal(); double histogram = macd.getHistogram(); // Check for MACD crossover if (macd.getPrevHistogram() < 0 && histogram > 0) { Print("Bullish MACD crossover at bar ", i); } else if (macd.getPrevHistogram() > 0 && histogram < 0) { Print("Bearish MACD crossover at bar ", i); } // Access historical values double macdHistory3BarsAgo = macd.getMACDHistory(3); } ``` -------------------------------- ### MQL5: Analyze Market Structure with MACD Source: https://context7.com/haza79/mt5-smart-money-concept-indicator/llms.txt Detects major market structure breaks (BOS), change of character (CHOCH), and inducement levels using MACD and fractal analysis. It requires initialization of MACD, BarData, MACDFractalClass, FractalClass, and MacdMarketStructureClass objects. The output includes trend information and locations of major swing points and inducement breaks. ```mql5 // Initialize market structure detector MACD macd; BarData barData; MACDFractalClass macdFractal; FractalClass fractal; MacdMarketStructureClass macdMarketStructure; macdFractal.Init(&macd, &barData); macdMarketStructure.init(&macdFractal, &barData, &fractal); // Process market structure for (int i = start; i < rates_total; i++) { macd.update(close[i], i, rates_total); macdFractal.Update(i); fractal.Calculate(i, high, low, rates_total); macdMarketStructure.update(i, rates_total); // Check current trend Trend currentTrend = macdMarketStructure.getLatestTrend(); string trendStr = macdMarketStructure.getLatestTrendAsString(); // Access major swing points if (macdMarketStructure.getLatestMajorHighIndex() != -1) { int majorHighBar = macdMarketStructure.getLatestMajorHighIndex(); double majorHighPrice = macdMarketStructure.getLatestmajorHighPrice(); Print("Major High: ", majorHighPrice, " at bar ", majorHighBar); } // Check for inducement break if (macdMarketStructure.isInducementBreak) { int inducementBar = macdMarketStructure.getInducementIndex(); Print("Inducement taken at bar: ", inducementBar, " - Potential reversal zone"); } } ``` -------------------------------- ### Detect Impulse and Pullback Swings (MQL5) Source: https://context7.com/haza79/mt5-smart-money-concept-indicator/llms.txt Identifies swing highs and lows by analyzing impulse moves and pullbacks in price action, with support for handling inside bars. This MQL5 code initializes and calculates swing points using the ImpulsePullbackDetectorClass. ```mql5 InsideBarClass insideBar; ImpulsePullbackDetectorClass impulsePullbackDetector; insideBar.Init(); impulsePullbackDetector.Init(&insideBar); // In OnCalculate loop for (int i = start; i < rates_total; i++) { insideBar.Calculate(i, rates_total, high, low); impulsePullbackDetector.Calculate(i, rates_total, high, low); // Access detected swing points if (impulsePullbackDetector.latestSwingHighIndex != -1) { double swingHighPrice = impulsePullbackDetector.latestSwingHighPrice; int swingHighBar = impulsePullbackDetector.latestSwingHighIndex; Print("Swing High detected at ", swingHighPrice, " on bar ", swingHighBar); } if (impulsePullbackDetector.latestSwingLowIndex != -1) { double swingLowPrice = impulsePullbackDetector.latestSwingLowPrice; int swingLowBar = impulsePullbackDetector.latestSwingLowIndex; Print("Swing Low detected at ", swingLowPrice, " on bar ", swingLowBar); } } ``` -------------------------------- ### Generate Candlestick Data from Swing Points (Python) Source: https://context7.com/haza79/mt5-smart-money-concept-indicator/llms.txt This Python script generates candlestick data (OHLC) from a list of swing points. It supports custom timeframes and saves the data to a CSV file compatible with MT5 import. It also includes optional chart visualization. Requires pandas and a plotting library. ```python swing_points = [ ("17/12/2024 10:45:00", 120417.55), ("18/12/2024 04:30:00", 116016.35), ("18/12/2024 14:15:00", 117281.69), ("18/12/2024 21:45:00", 114512.6), ("19/12/2024 22:15:00", 118323.3) ] try: # Generate candlestick data with 15-minute timeframe df = generate_candlesticks_from_swings(swing_points, timeframe_minutes=15) # Display generated data print(df.head()) # Output columns: DATE, TIME, OPEN, HIGH, LOW, CLOSE # Save to CSV for MT5 import df.to_csv("candlestick_data.csv", index=False) print("Data saved to candlestick_data.csv") # Visualize candlestick chart plot_candlestick(df) except ValueError as e: print(f"Error: {e}") # Advanced usage: Multiple timeframes swing_points_btc = [ ("01/01/2025 00:00:00", 42000.0), ("02/01/2025 12:00:00", 43500.0), ("03/01/2025 18:00:00", 41800.0) ] # Generate hourly data df_hourly = generate_candlesticks_from_swings(swing_points_btc, timeframe_minutes=60) # Generate 5-minute data for granular analysis df_5min = generate_candlesticks_from_swings(swing_points_btc, timeframe_minutes=5) print(f"Generated {len(df_hourly)} hourly candles") print(f"Generated {len(df_5min)} 5-minute candles") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.