Indicator · Pine Script v6 · Own pane

Jurik Composite Fractal Behavior

by mihakralj

The Jurik Composite Fractal Behavior indicator computes a weighted average of efficient trend lengths as a composite fractal behavior value, also known as the trend duration index.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code77
Settings2inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

77 lines of Pine Script v6 from lib/momentum/cfb/cfb.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

cfb.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Jurik Composite Fractal Behavior", "CFB", overlay=false)

//@function Calculates Jurik Composite Fractal Behavior (Trend Duration Index)
//@param   source Series to calculate CFB from
//@param   maxLength Maximum lookback length (default 192, lengths 2,4,6,...,maxLength used)
//@returns CFB value - weighted average of efficient trend lengths, minimum 1
cfb(series float source, simple int maxLength = 192) =>
    // Generate lengths array: 2, 4, 6, ..., maxLength
    int numLengths = int(maxLength / 2)

    // Persistent state
    var float prevCfb = 1.0
    var array<float> runningSums = array.new_float(numLengths, 0.0)

    float currentVol = bar_index == 0 ? 0.0 : math.abs(source - source[1])

    float sumWeightedLen = 0.0
    float sumWeights = 0.0

    // Update running sums and calculate ratios for each length
    for i = 0 to numLengths - 1
        int L = (i + 1) * 2

        // Update running sum of volatility
        float oldSum = array.get(runningSums, i)
        float volToRemove = bar_index > L ? math.abs(source[L] - source[L + 1]) : 0.0
        float newSum = oldSum + currentVol - volToRemove
        array.set(runningSums, i, newSum)

        // Skip if not enough bars
        if bar_index < L
            continue

        // Skip if very small volatility
        if newSum < 1e-12
            continue

        // Net move over L bars
        float netMove = math.abs(source - source[L])
        float ratio = netMove / newSum

        if ratio >= 0.25
            sumWeightedLen += float(L) * ratio
            sumWeights += ratio

    // Calculate CFB
    float cfbVal = 1.0
    if sumWeights > 0.25
        cfbVal := sumWeightedLen / sumWeights
    else
        cfbVal := prevCfb > 1.0 ? prevCfb * 0.5 : 1.0

    if cfbVal < 1.0
        cfbVal := 1.0

    cfbVal := math.round(cfbVal)
    if cfbVal < 1.0
        cfbVal := 1.0

    prevCfb := cfbVal
    cfbVal

// ---------- Main loop ----------

// Inputs
i_maxLength = input.int(192, "Max Length", minval=4, step=2, tooltip="Maximum lookback length. Lengths 2,4,6,...,maxLength are used")
i_source = input.source(close, "Source")

// Calculation
cfb_value = cfb(i_source, i_maxLength)

// Plot
plot(cfb_value, "CFB", color=color.yellow, linewidth=2)
hline(1, "Min", color=color.gray, linestyle=hline.style_dotted)

Overview

Jurik Composite Fractal Behavior processes a user-specified source series using a max lookback length and calculates ratios based on net price moves and volatility sums. The indicator plots the resulting CFB value in a separate pane on the chart. Main settings allow adjusting the maximum length and selecting the input source. It signals trend behavior through these calculated values but provides no built-in entry or exit rules, as it is an indicator only. It draws strictly in a separate pane and does not repaint signals on the live bar.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Max Lengthint192i_maxLength
Sourcesourceclosei_source
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 10 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of [RS]Standardized Trend Map

ADX Histogram

by harryguiacorn
219 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers