Indicator · Pine Script v6 · On the chart

Fractal Chaos Bands (FCB)

by mihakralj

Calculates and plots Fractal Chaos Bands directly on the price chart.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code73
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

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

fcb.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Fractal Chaos Bands (FCB)", "FCB", overlay=true)

//@function Calculates Fractal Chaos Bands based on fractal highs and lows
//@param period Lookback period for highest/lowest calculation
//@returns [upper_band, lower_band] Fractal Chaos Band values
//@optimized Uses monotonic deque for O(1) amortized complexity
fcb(simple int period) =>
    if period <= 0
        runtime.error("Period must be greater than 0")
    bool is_fractal_high = high[1] > high[2] and high[1] > high[0]
    bool is_fractal_low = low[1] < low[2] and low[1] < low[0]
    var float hi_fractal = high
    var float lo_fractal = low
    if is_fractal_high
        hi_fractal := high[1]
    if is_fractal_low
        lo_fractal := low[1]
    var hi_deque = array.new_int(0)
    var hi_buffer = array.new_float(period, na)
    var int hi_current_index = 0
    float hi_current_val = nz(hi_fractal)
    array.set(hi_buffer, hi_current_index, hi_current_val)
    while array.size(hi_deque) > 0 and array.get(hi_deque, 0) <= bar_index - period
        array.shift(hi_deque)
    while array.size(hi_deque) > 0
        int last_index = array.get(hi_deque, array.size(hi_deque) - 1)
        int buffer_lookup = last_index % period
        if array.get(hi_buffer, buffer_lookup) <= hi_current_val
            array.pop(hi_deque)
        else
            break
    array.push(hi_deque, bar_index)
    int highest_index = array.get(hi_deque, 0)
    int highest_buffer_index = highest_index % period
    float upper_band = array.get(hi_buffer, highest_buffer_index)
    hi_current_index := (hi_current_index + 1) % period
    var lo_deque = array.new_int(0)
    var lo_buffer = array.new_float(period, na)
    var int lo_current_index = 0
    float lo_current_val = nz(lo_fractal)
    array.set(lo_buffer, lo_current_index, lo_current_val)
    while array.size(lo_deque) > 0 and array.get(lo_deque, 0) <= bar_index - period
        array.shift(lo_deque)
    while array.size(lo_deque) > 0
        int last_index = array.get(lo_deque, array.size(lo_deque) - 1)
        int buffer_lookup = last_index % period
        if array.get(lo_buffer, buffer_lookup) >= lo_current_val
            array.pop(lo_deque)
        else
            break
    array.push(lo_deque, bar_index)
    int lowest_index = array.get(lo_deque, 0)
    int lowest_buffer_index = lowest_index % period
    float lower_band = array.get(lo_buffer, lowest_buffer_index)
    lo_current_index := (lo_current_index + 1) % period
    [upper_band, lower_band]

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

// Inputs
i_period = input.int(20, "Period", minval=1, maxval=999)
plot_fractal_points = input.bool(false, "Show Fractal Points")

// Calculation
[upper_band, lower_band] = fcb(i_period)

// Plots
p_upper = plot(upper_band, "Upper Band", color=color.yellow, linewidth=2)
p_lower = plot(lower_band, "Lower Band", color=color.yellow, linewidth=2)
fill(p_upper, p_lower, color=color.new(color.blue, 90), title="Band Fill")

Overview

The indicator identifies local fractal swing highs and lows, tracking the highest fractal high and lowest fractal low across a user-specified lookback period using monotonic deques. The resulting upper and lower channel boundaries visualize dynamic support and resistance zones, filled with a translucent background. User settings allow adjusting the lookback period and toggling fractal point displays. The indicator produces no standalone trade signals or exit rules.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volatility & bands, Support & resistance, Breakout

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
Periodint20i_period
Show Fractal Pointsboolfalseplot_fractal_points
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

47 stars

The Donchian Channels indicator plots the middle basis line as the average of the high and low over the user-defined period. It also draws the upper band as the highest high and the lower band as the lowest low across the same period on the price chart. The ma

Indicator v6 Volatility & bandsSupport & resistance
Updated 8 months ago · MIT GitHub repository of Donchian Channels (DCHANNEL)
43 stars

This indicator plots Donchian channel bands and a midline on the price chart. It finds the highest and lowest values over a user-set length, then draws the upper band, lower band, and their average as the basis. The source setting chooses high and low, or the

Indicator v4 Volatility & bandsBreakout
Updated 1 year ago · None stated GitHub repository of Donchian Channels Experiment

Zen ABR Against

by Zen-Tim
29 stars

This overlay indicator measures average bar range as a simple moving average of high minus low, then draws short horizontal ticks at one to four times that range above and below the close. The user chooses which multipliers appear, their colors, and the line w

Indicator v6 Volatility & bandsSupport & resistance
Updated 2 weeks ago · MIT GitHub repository of Zen ABR Against

This indicator identifies and plots price compression zones directly on the price chart using multi-module scoring. It measures ATR compression, ADX chop levels, boundary touches, volume dry-up, and historical pivot levels to identify consolidation areas and s

Indicator v6 BreakoutSupport & resistance
Updated yesterday · MIT GitHub repository of CoilForge Zones [WavesUnchained]

Dereköy-Darvas

by Kalumur
4 stars

The Dereköy-Darvas indicator combines Darvas Box boundary levels with dual Bollinger Bands plotted directly on the main price chart. It calculates top and bottom box lines based on recent high and low extremes to outline price consolidation zones. Simultaneous

Indicator v5 Volatility & bandsSupport & resistance
Updated 2 years ago · None stated GitHub repository of Dereköy-Darvas
3 stars

This overlay indicator plots ATR-based horizontal levels around the previous close of a selected higher timeframe. A trading-type input maps day, multiday, swing, position, and long-term modes to daily through yearly periods. It draws trigger bands from a perc

Indicator v5 Volatility & bandsSupport & resistance Repaints
Updated 5 months ago · None stated GitHub repository of ATR Levels + CALL/PUT

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