Search
GBP
Trading Tools
    Menu Close

    Genetic Algorithm Smoothed MACD for cTrader

    Genetic Algorithm Smoothed MACD for cTrader


    Limited Support

    A MACD that tunes itself. This cTrader indicator uses a compact genetic algorithm to discover the best EMA smoothing factors for the fast leg, the slow leg, and the signal line. The fitness blends smoothness, responsiveness to price momentum, and healthy separation between MACD and signal, producing a cleaner histogram and earlier, steadier crossovers. Quantitative and Experimental Model.
    (OS) Type: Windows & Mac OS Compatible
    Current version: 1.0.0
    Updated: Wednesday, 13 August 2025

    cTrader Indicator

    Need a cTrader broker?  Open a demo account

    Educational use only: Read our disclaimer

    £0.00 Excl. VAT.

    Free for personal use under our license agreement. Redistribution & resale are strictly prohibited.

    cTrader Software





    Overview

    Most traders meet MACD through the classic recipe using fixed periods. Fixed settings are simple, but markets shift. The idea here is to let the data pick the smoothing, without throwing away what makes MACD so readable. A lightweight genetic algorithm searches the space of EMA alphas, under a fitness that rewards calm curves, timely reaction to price changes, and a clear gap between MACD and signal. You keep the familiar look and feel, while the internals quietly adapt.

     

    cTrader Genetic Algorithm Smoothed MACD Indicator

     

    How the Algorithm is Calculated

    The Genetic Algorithm Smoothed MACD for cTrader takes the classic Moving Average Convergence Divergence formula and replaces its fixed smoothing periods with adaptive values discovered through a compact genetic optimisation process. Instead of relying on static fast, slow, and signal settings, the indicator evaluates thousands of possible EMA combinations against recent market data, scoring each by how smooth, responsive, and well separated its MACD and signal lines are. The result is a MACD that adjusts to current price behaviour, producing cleaner crossovers and more stable histogram patterns without losing the familiar visual style traders rely on.

    Training window

    1. Select the most recent block of bars, default 1500.
    2. Build arrays for close prices and the one-bar rate of change, ROC1.

    Chromosome definition

    • Each candidate solution is three EMA smoothing factors, alphafast, alphaslow, alphasig.
    • Map period to alpha with α = 2 ⁄ (period + 1), constrain periods to a practical range.

    Population initialization

    • Create a population of candidate triplets sampled from the allowed period ranges.
    • Enforce fast smoothing greater than slow smoothing for logical ordering.

    Evaluate a candidate

    1. Compute EMAfast(Close) and EMAslow(Close) using alphafast and alphaslow.
    2. Compute MACD = EMAfast − EMAslow.
    3. Compute Signal = EMAsig(MACD) using alphasig.
    4. Compute Histogram = MACD − Signal.

    Fitness components

    • Smoothness: 1 ⁄ (1 + std of first difference of MACD).
    • Responsiveness: correlation of MACD with ROC1, mapped from −1, 1 to 0, 1.
    • Separation: tanh of mean absolute Histogram divided by its standard deviation plus a small epsilon.

    Total fitness

    F = ws × Smoothness + wr × Responsiveness + wsep × Separation.

    Evolution loop

    1. Sort by fitness, carry forward the top candidates for elitism.
    2. Select parents with small tournaments over the population.
    3. Apply a blend crossover to produce children, then mutate each alpha with a small chance, mutating in period space for natural scale.
    4. Clamp alphas to valid bounds and keep fast greater than slow.
    5. Repeat for the chosen number of generations.

    Adopt the best alphas

    • Pick the highest fitness triplet and set alphafast, alphaslow, alphasig for live calculation.
    • If periodic re-optimisation is enabled, repeat after the chosen bar count.

    Live updates on every bar

    1. MACDt = EMAalpha fast(Close)t − EMAalpha slow(Close)t.
    2. Signalt = EMAalpha sig(MACD)t.
    3. Histogramt = MACDt − Signalt.
    4. Mark Buy when MACD crosses above Signal, mark Sell when MACD crosses below Signal.

    Reference identities

    • EMA update: EMAt = α × Pricet + (1 − α) × EMAt−1.
    • Alpha from period: α = 2 ⁄ (period + 1).

     

    Why is this Indicator Special

    • It stays MACD, so it is instantly readable to the eye, yet it self-tunes for the current market regime.

    • Fitness is not a single target; it balances three qualities that matter in practice: a smooth line, a timely response, and an expressive histogram.

    • The optimiser is compact and bounded, so it is practical on live charts without exotic dependencies.

     

    Key Features

    • Self-tuning MACD with compact genetic optimisation, no external data required.

    • Balanced fitness that values smooth lines, timely reaction, and a readable histogram.

    • Buy and sell markers on crossovers, plotted at the MACD level for visual precision.

    • Optional periodic retraining for evolving markets, or one-shot training for stability.

    • Safe defaults, with a classic MACD fallback at a single switch.

     

    How to Use it for Trading

    You can use this indicator to identify and study recurring price behaviours around holidays. For example:

    • Trend confirmation
      Favour long bias when the MACD is above the signal and the histogram stays mostly positive. Favour short bias when the MACD is below the signal and the histogram stays mostly negative.

    • Crossovers
      Use the plotted buy and sell markers as entry signals, then look for agreement with price structure, such as breakouts or pullbacks to moving averages on your timeframe.

    • Divergence
      Watch for the price making a new extreme while MACD does not. The smoothed line reduces noise so that divergence can stand out.

    • Multi-timeframe check
      Consider aligning a fast chart for entries with a slower chart for bias; the adaptive smoothing helps both ends meet in the middle.

     

    Inputs & Parameters

    Inputs
    Parameter Default or Type Description
    Optimization
    Use Genetic Optimisation true Enable self-tuning of EMA alphas using the genetic search. Disable to use classic MACD periods.
    Optimise On Start Only true Run the optimiser once on load. Turn off to allow periodic re-optimisation.
    Re-optimise Every N Bars 200 When periodic re-optimisation is enabled, retrain after this many new bars.
    Optimisation Window, bars 1500 Number of recent bars used for training and fitness evaluation.
    GA Settings
    Population Size 28 Number of candidate alpha triplets per generation.
    Generations 40 Number of evolutionary steps before choosing the best solution.
    Mutation Rate 0.12 Chance that each alpha is perturbed during reproduction.
    Random Seed 0 Zero uses time based seed. Set a number for repeatable results.
    Fitness Weights
    w Smoothness 0.35 Weight for stability of the MACD curve.
    w Responsiveness 0.40 Weight for correlation with one bar momentum.
    w Separation 0.25 Weight for the size and clarity of the histogram.
    Fallback Classic MACD
    Classic Fast Period 12 Fast EMA period when GA is disabled.
    Classic Slow Period 26 Slow EMA period when GA is disabled.
    Classic Signal Period 9 Signal EMA period when GA is disabled.

     

    Formulas

    The Genetic Algorithm Smoothed MACD builds on the classic MACD equations but replaces fixed EMA periods with dynamically optimised smoothing factors. Below are the core formulas that define how EMA values, MACD, signal, histogram, and the genetic algorithm’s fitness metrics are calculated.

    EMA and Alpha

    EMAt = α × Pricet + (1 − α) × EMAt−1

    α = 2 ⁄ (Period + 1)

    MACD Family

    MACDt = EMAαfast(Close)t − EMAαslow(Close)t

    Signalt = EMAαsig(MACD)t

    Histogramt = MACDt − Signalt

    Rate of Change for Responsiveness

    ROC1(t) = (Closet − Closet−1) ⁄ Closet−1

    Fitness Components

    Smoothness = 1 ⁄ (1 + std( ΔMACD ))

    Responsiveness = ( corr(MACD, ROC1) + 1 ) ⁄ 2

    Separation = tanh ( E[ |Histogram| ] ⁄ ( std(Histogram) + ε ) )

    Total Fitness

    F = ws × Smoothness + wr × Responsiveness + wsep × Separation

     

    No optimizer can defeat regime change. If the character of the market flips faster than your retraining cadence, performance may lag. Indicators infer from past behavior, a sensible risk plan and validation on out of sample data are still required.

     

    How To Install & Remove

    First, ensure that you have the cTrader trading platform installed. Then, unzip the file and double-click it to install the platform automatically.

     

    Help Using This Indicator

    If you need help using this indicator, try asking cTrader Sensei, our free AI assistant dedicated to the cTrader platform, rated 4.9 out of 5 in the ChatGPT Store. It can guide you through setup, usage, and troubleshooting with clear, step-by-step support.

    If you still need assistance, feel free to post your question on our product support forum, where our team and community can help.

     

    Need a Broker

    If you're still looking for a trustworthy broker, visit our top cTrader broker site.