Indicator · Pine Script v5 · Own pane

Musashi Fractal Dimension v2

by regalouisei· code credited to Musashi-Alchemist

This TradingView Pine Script indicator plots the Fractal Dimension Index (FDI) calculated from multiple length parameters for slow fast and ultra slow variants.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code352
Settings40inputs
LicenceNone statedfile: MPL-2.0
Last update8 months ago25 Feb 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

352 lines of Pine Script v5 from pinescript/editors_picks/musashi-fractal-dimension.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

musashi-fractal-dimension.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Musashi-Alchemist

//@version=5
indicator(title = "Musashi_Fractal_Dimension_v2", overlay = false, max_bars_back = 5000)

//===================================
// GENERAL INPUTS
//===================================
// ----------------------------------
show_fdi = input.bool(true, title = "FDI      ", group='STUDIES', inline='studies')
show_rsi = input.bool(false, title = "RSI      ", group='STUDIES', inline='studies')
show_bbwp = input.bool(false, title = "BBWP", group='STUDIES', inline='studies')
// ----------------------------------

//===================================
// FDI INPUTS
//===================================
// ----------------------------------
fdi_src    = input.source(close, title = "FDI Source        ", group='FDI - FRACTAL DIMENSION INDEX', inline='fdi_a')
fdi_length = input.int(21, title = "Slow FDI Length   ", minval = 2, group='FDI - FRACTAL DIMENSION INDEX', inline='fdi_0')
fdi_length_2 = input.int(13, title = "Fast FDIs Length 1:", minval = 2, group='FDI - FRACTAL DIMENSION INDEX', inline='fdi_1')
fdi_length_3 = input.int(12, title = "2:", minval = 2, group='FDI - FRACTAL DIMENSION INDEX', inline='fdi_1')
fdi_length_4 = input.int(11, title = "3:", minval = 2, group='FDI - FRACTAL DIMENSION INDEX', inline='fdi_1')
// ----------------------------------
bandLength = input.int(21, minval = 1, title = "Baseline Length   ", group='FDI - FRACTAL DIMENSION INDEX', inline='base_1')
// ----------------------------------
ultra_show_fdi = input.bool(false, title = "Show Ultra-Slow FDI", group='ULTRA-SLOW FDI', inline='base_0')
ultra_fdi_length = input.int(34, title = "     Length", minval = 2, group='ULTRA-SLOW FDI', inline='base_0')
// ----------------------------------
ultra_show_fdi_baseline = input.bool(false, title = "Show Baseline", group='ULTRA-SLOW FDI', inline='base_2')
ultra_bandLength = input.int(15, minval = 1, title = "          Length", group='ULTRA-SLOW FDI', inline='base_2')
// ----------------------------------

//===================================
// PLOT HORIZONTAL LINES
//===================================
// ----------------------------------
adjust_number = show_fdi or ultra_show_fdi or ultra_show_fdi_baseline ? 1 : 0
// ----------------------------------
p_scaleHi   = hline (show_bbwp or show_rsi ?  1 + adjust_number : na, 'High', color.new(#f57c00,50), hline.style_dotted )
p_scaleHi_1 = hline (show_fdi or show_bbwp or show_rsi ? 0.8 + adjust_number : na, 'Level 6', color.new(#b71c1c,50), hline.style_dotted )
p_scaleHi_2 = hline (show_fdi or show_rsi ? 0.75 + adjust_number : na,'Level 5', color.new(#b71c1c,50), hline.style_dotted )
p_scaleHi_3 = hline (show_fdi? 0.6 + adjust_number : na, 'Level 4', color.new(#b71c1c,50), hline.style_dotted )
p_midLine   = hline (show_fdi or show_bbwp or show_rsi or ultra_show_fdi or ultra_show_fdi_baseline? 0.5 + adjust_number : na, 'Mid-Line', color.new(#f57c00,42), hline.style_dashed )
p_scaleLo   = hline (show_fdi ? 0.4 + adjust_number : na, 'Level 3', color.new(#b71c1c,50), hline.style_dotted )
p_scaleLo_1 = hline (show_fdi or show_rsi ? 0.25 + adjust_number : na,'Level 2', color.new(#b71c1c,50), hline.style_dotted )
p_scaleLo_2 = hline (show_fdi or show_bbwp or show_rsi ? 0.2 + adjust_number : na, 'Level 1', color.new(#b71c1c,50), hline.style_dotted )
p_scaleLo_3 = hline (show_bbwp or show_rsi ? 0 + adjust_number : na, 'Low', color.new(#f57c00,50), hline.style_dotted )
// ----------------------------------

//===================================
// FDI CALCULATIONS
//===================================
// ----------------------------------
calculate_FDI(fdi_src, fdi_length) =>
    highest_high = ta.highest(fdi_src, fdi_length)
    lowest_low   = ta.lowest(fdi_src,  fdi_length)
    // ----------------------------------
    diff = float(0.0)
    length = float(0.0)
    for i = 1 to fdi_length - 1
        diff := (fdi_src[i] - lowest_low) / (highest_high - lowest_low)
        length := length + math.sqrt(math.pow(diff[i] - diff[i+1], 2) + (1 / math.pow(fdi_length, 2)))

    fdi = 1 + (math.log(length) + math.log(2)) / math.log(2*fdi_length)
    fdi
// ----------------------------------
fdi  = float(0.0)
fdi := calculate_FDI(fdi_src, fdi_length)
// ----------------------------------
fdi_2  = float(0.0)
fdi_2 := calculate_FDI(fdi_src, fdi_length_2)
// ----------------------------------
fdi_3  = float(0.0)
fdi_3 := calculate_FDI(fdi_src, fdi_length_3)
// ----------------------------------
fdi_4  = float(0.0)
fdi_4 := calculate_FDI(fdi_src, fdi_length_4)
// ----------------------------------
offs = (1.6185 * ta.stdev(fdi, bandLength))  
ma = ta.sma(fdi, bandLength)
// ------------------------------------
fdi_color = fdi_2 > fdi ? show_fdi ? color.new(color.silver,25) : na :  show_fdi ? color.new(#e92727, 0) : na
fdi_plot   = plot(show_fdi ? fdi : na, title = "Slow FDI", color = fdi_color, linewidth=2)
// ----------------------------------
fdi_color_2 = fdi_2 > fdi ? show_fdi ? color.new(color.silver,66) : na :  show_fdi ? color.new(#e92727, 56) : na
fdi_plot_2   = plot(show_fdi ? fdi_2 : na, title = "Fast FDI 1", color = fdi_color_2, linewidth=2)
// ----------------------------------
fdi_color_3 = fdi_3 > fdi_2 ? show_fdi ? color.new(#434651,46) : na :  show_fdi ? color.new(#e92727, 45) : na
fdi_plot_3   = plot(show_fdi ? fdi_3 : na, title = "Fast FDI 2", color = fdi_color_3, linewidth=1)
// ----------------------------------
fdi_color_4 = fdi_4 > fdi_3 ? show_fdi ? color.new(#434651,46) : na :  show_fdi ? color.new(#e92727, 62) : na
fdi_plot_4   = plot(show_fdi ? fdi_4 : na, title = "Fast FDI 3", color = fdi_color_4, linewidth=1)
// ----------------------------------
plot(show_fdi and ta.cross(fdi, fdi_2) and fdi>=fdi_2? fdi : na, title = "FDI_0 x FDI_1 ABOVE 1.5", color = color.white, linewidth = 2, style = plot.style_circles) //, title = "Slow FDI"
plot(show_fdi and ta.cross(fdi_3, fdi_2) and fdi_3<=fdi_2 and fdi_3>=1.5? fdi_2 : na, title = "FDI_1 x FDI_2 ABOVE 1.5", color = color.new(color.silver, 28), linewidth = 2, style = plot.style_circles)
plot(show_fdi and ta.cross(fdi_4, fdi_3) and fdi_4<=fdi_3 and fdi_4>=1.5? fdi_3 : na, title = "FDI_2 x FDI_3 ABOVE 1.5", color = color.new(color.silver, 36), linewidth = 2, style = plot.style_circles)
// ----------------------------------
plot(show_fdi and ta.cross(fdi, fdi_2) and fdi<=fdi_2? fdi : na, title = "FDI_0 x FDI_1 BELOW 1.4", color = #ff8919, linewidth = 2, style = plot.style_circles)
plot(show_fdi and ta.cross(fdi_3, fdi_2) and fdi_3>=fdi_2 and fdi_3<=1.4? fdi_2 : na, title = "FDI_1 x FDI_2 BELOW 1.4", color = color.new(#e92727, 28), linewidth = 2, style = plot.style_circles)
plot(show_fdi and ta.cross(fdi_4, fdi_3) and fdi_4>=fdi_3 and fdi_4<=1.4? fdi_3 : na, title = "FDI_2 x FDI_3 BELOW 1.4", color = color.new(#e92727, 36), linewidth = 2, style = plot.style_circles)
// ----------------------------------
upb = fdi + offs // Upper Bands
dnb = fdi - offs // Lower Bands
mid = ((ma + offs) + (ma - offs)) / 2

midl = plot(show_fdi ? mid : na, "FDI Baseline", color = color.new(#7e57c2, 38), linewidth = 2, style=plot.style_line)
// ----------------------------------
plot(show_fdi and ta.cross(fdi, mid) ? mid : na, color = color.new(#7e57c2, 0), title = "Primary FDI x Baseline", linewidth = 3, style = plot.style_circles) //plot.style_cross
// ----------------------------------

// ----------------------------------
// FDI - ULTRA SLOW
// ----------------------------------
ultra_fdi  = float(0.0)
ultra_fdi := calculate_FDI(fdi_src, ultra_fdi_length)
// ----------------------------------
ultra_offs = (1.6185 * ta.stdev(ultra_fdi, ultra_bandLength))  
ultra_ma = ta.sma(ultra_fdi, ultra_bandLength)
// ----------------------------------
ultra_upb = ultra_fdi + ultra_offs // Upper Bands
ultra_dnb = ultra_fdi - ultra_offs // Lower Bands
ultra_mid = ((ultra_ma + ultra_offs) + (ultra_ma - ultra_offs)) / 2
// ----------------------------------
ultra_midl = plot(ultra_show_fdi_baseline ? ultra_mid : na, "Ultra-Slow FDI Baseline", color = color.new(#5d606b, 28), linewidth = 2, style=plot.style_line)
// ----------------------------------
plot(ultra_show_fdi_baseline and ta.cross(ultra_fdi, ultra_mid) ? ultra_mid : na, color = color.new(#5d606b, 12), title = "Ultra Slow Baseline x Short Term baseline", linewidth = 3, style = plot.style_circles) //plot.style_cross
// ----------------------------------
ultra_fdi_color = ultra_show_fdi and (ultra_mid < ultra_fdi) ? color.new(color.silver,0) :  color.new(#e92727, 0)
ultra_fdi_plot   = plot(ultra_show_fdi ? ultra_fdi : na, title = "Ultra-Slow FDI", color = ultra_fdi_color, linewidth=2)
// ------------------------------------

//===================================
//=== RSI INPUTS
//===================================
// ----------------------------------
rsiPeriod = input.int(9, minval=1, title='Primary RSI Period', group='RSI - RELATIVE STERNGTH INDEX', inline='base_1')
second_rsiPeriod = input.int(7, minval=1, title='Secondary RSI Period', group='RSI - RELATIVE STERNGTH INDEX', inline='base_1')
// ----------------------------------
rsibandLength = input.int(21, minval = 1, title = "Baseline Length   ", group='RSI - RELATIVE STERNGTH INDEX', inline='base_1')
// ----------------------------------

//===================================
//=== RSI CALCULATIONS & PLOT
//===================================
// ----------------------------------
prim_rsi = ta.rsi(close, rsiPeriod)
second_rsi = ta.rsi(close, second_rsiPeriod)
// ----------------------------------
p_rsi_f = show_rsi ?  adjust_number + prim_rsi/100 : na
s_rsi_f = show_rsi ?  adjust_number + second_rsi/100 : na
// ----------------------------------
offs_rsi = (1.6185 * ta.stdev(p_rsi_f, rsibandLength))  
ma_rsi = ta.sma(p_rsi_f, rsibandLength)
// ----------------------------------
upb_rsi = p_rsi_f + offs_rsi // Upper Bands
dnb_rsi = p_rsi_f - offs_rsi // Lower Bands
mid_rsi = ((ma_rsi + offs_rsi) + (ma_rsi - offs_rsi)) / 2
// ----------------------------------
midl_rsi = plot(show_rsi ? mid_rsi : na, "RSI Baseline", color = color.new(#1848cc, 25), linewidth = 2, style=plot.style_line)
plot(show_rsi and ta.cross(p_rsi_f, mid_rsi) ? mid_rsi : na, color = color.new(#1848cc, 0) , title = "RSI x Baseline", linewidth = 3, style = plot.style_circles) //plot.style_cross
// ----------------------------------
prim_rsi_plot = plot(show_rsi ? p_rsi_f : na, 'Primary RSI', color=color.new(#3179f5, 60), linewidth=2) //#f57c00 color.white
sec_rsi_plot = plot(show_rsi ? s_rsi_f : na, 'Secondary RSI', color=color.new(#3179f5, 80), linewidth=2) //#d1d4dc
// ----------------------------------

//===================================
//=== RSI DIVERGENCES & PLOT
//===================================
// ----------------------------------
// Inputs 
lbR = input(title='Pivot Lookback Right', defval=2, group='RSI - DIVERGENCES', inline='div_1')
lbL = input(title='Pivot Lookback Left', defval=9, group='RSI - DIVERGENCES', inline='div_1')
// ----------------------------------
rangeUpper = input(title='Max of Lookback   ', defval=120, group='RSI - DIVERGENCES', inline='div_2')
rangeLower = input(title='    Min of Lookback', defval=1, group='RSI - DIVERGENCES', inline='div_2')
// ----------------------------------
plotBull = input(title='Bullish', defval=true, group='RSI - DIVERGENCES', inline='div_3')
plotBear = input(title='Bearish       ', defval=true, group='RSI - DIVERGENCES', inline='div_3')
plotHiddenBull = input(title='Hidden Bullish', defval=true, group='RSI - DIVERGENCES', inline='div_3')
plotHiddenBear = input(title='Hidden Bearish', defval=true, group='RSI - DIVERGENCES', inline='div_3')
// ----------------------------------
showLabels = input(title='Show Labels', defval=false, group='RSI - DIVERGENCES', inline='div_4')
// ----------------------------------
// Color setup
bullColor = color.new(#5b9cf6, 28)
hiddenBullColor = color.new(#5b9cf6, 25)  //orange: #ff9800
bearColor = color.new(#d32f2f, 28)  //red: #b71c1c
hiddenBearColor = color.new(#d32f2f, 25)  //gray:#9598a1 red:#d32f2f
textColor = #d1d4dc  //color.white
noneColor = color.new(color.white, 100)
// ----------------------------------
bull_line_width = 2
bear_line_width = 2
// ----------------------------------
plFound = na(ta.pivotlow(p_rsi_f, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(p_rsi_f, lbL, lbR)) ? false : true
// ----------------------------------
_inRange(cond) =>
    bars = ta.barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper
// ----------------------------------

// ==================
// RSI DIVERGENCES
// ==================
// ----------------------------------
// Regular Bullish
// ----------------------------------
oscHL = p_rsi_f[lbR] > ta.valuewhen(plFound, p_rsi_f[lbR], 1) and _inRange(plFound[1]) // Osc: Higher Low
priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1) // Price: Lower Low
bullCond = plotBull and priceLL and oscHL and plFound // Regular Bull condition
plot(plFound ? p_rsi_f[lbR] : na, offset=-lbR, title='Regular Bullish line', linewidth=2, color=show_rsi and bullCond ? bullColor : na)
plotshape(show_rsi and showLabels and bullCond ? p_rsi_f[lbR] : na, offset=-lbR, title='Regular Bullish Label', text='R', style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor)
// ----------------------------------
// Hidden Bullish
// ----------------------------------
oscLL = p_rsi_f[lbR] < ta.valuewhen(plFound, p_rsi_f[lbR], 1) and _inRange(plFound[1]) // Osc: Lower Low
priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1) // Price: Higher Low
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound // Hidden Bull condition
plot(plFound ? p_rsi_f[lbR] : na, offset=-lbR, title='Hidden Bullish line', linewidth=2, color=show_rsi and hiddenBullCond ? hiddenBullColor : na)
plotshape(show_rsi and showLabels and hiddenBullCond ? p_rsi_f[lbR] : na, offset=-lbR, title='Hidden Bullish Label', text=' H', style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor)
// ----------------------------------
// Regular Bearish
// ----------------------------------
oscLH = p_rsi_f[lbR] < ta.valuewhen(phFound, p_rsi_f[lbR], 1) and _inRange(phFound[1]) // Osc: Lower High
priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1) // Price: Higher High
bearCond = plotBear and priceHH and oscLH and phFound // Regular Bear condition
plot(phFound ? p_rsi_f[lbR] : na, offset=-lbR, title='Regular Bearish line', linewidth=2, color=show_rsi and bearCond ? bearColor : na)
plotshape(show_rsi and showLabels and bearCond ? p_rsi_f[lbR] : na, offset=-lbR, title='Regular Bearish Label', text='R', style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor)
// ----------------------------------
// Hidden Bearish
// ----------------------------------
oscHH = p_rsi_f[lbR] > ta.valuewhen(phFound, p_rsi_f[lbR], 1) and _inRange(phFound[1]) // Osc: Higher High
priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1) // Price: Lower High
hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound // Hidden Bear condition
plot(phFound ? p_rsi_f[lbR] : na, offset=-lbR, title='Hidden Bearish line', linewidth=2, color=show_rsi and hiddenBearCond ? hiddenBearColor : na)
plotshape(show_rsi and showLabels and hiddenBearCond ? p_rsi_f[lbR] : na, offset=-lbR, title='Hidden Bearish Label', text='H', style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor)
// ----------------------------------


//===================================
// BBWP
//===================================
// ----------------------------------

hide_lava = input.bool    (true, 'Hide high values', inline='4', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
// ----------------------------------


//===================================
// BBWP FUNCTIONS
//===================================
// ----------------------------------
f_maType ( _price, _len, _type ) =>
    _type == 'SMA' ? ta.sma ( _price, _len ) : _type == 'EMA' ? ta.ema ( _price, _len ) : ta.vwma ( _price, _len )
// ----------------------------------
f_bbwp ( _price, _bbwLen, _bbwpLen, _type ) =>
    float _basis = f_maType ( _price, _bbwLen, _type )
    float _dev = ta.stdev ( _price, _bbwLen )
    _bbw = ( _basis + _dev - ( _basis - _dev )) / _basis
    _bbwSum = 0.0
    _len = bar_index < _bbwpLen ? bar_index : _bbwpLen
    for _i = 1 to _len by 1
        _bbwSum += ( _bbw[_i] > _bbw ? 0 : 1 )
        _bbwSum
    _return = bar_index >= _bbwLen ? ( _bbwSum / _len) * 100 : na
    _return
// ----------------------------------
f_clrSlct ( _percent, _select, _type, _solid, _array1 ) =>
    _select == 'Solid' ? _solid : array.get (_array1, math.round ( _percent ) )
// ----------------------------------
var c_prcntSpctrm2 = array.new_color(na)
if barstate.isfirst
    array.push ( c_prcntSpctrm2, #0000FF )
    array.push ( c_prcntSpctrm2, #0200FC ), array.push ( c_prcntSpctrm2, #0500F9 ), array.push ( c_prcntSpctrm2, #0700F7 ), array.push ( c_prcntSpctrm2, #0A00F4 ), array.push ( c_prcntSpctrm2, #0C00F2 ),
    array.push ( c_prcntSpctrm2, #0F00EF ), array.push ( c_prcntSpctrm2, #1100ED ), array.push ( c_prcntSpctrm2, #1400EA ), array.push ( c_prcntSpctrm2, #1600E8 ), array.push ( c_prcntSpctrm2, #1900E5 ),
    array.push ( c_prcntSpctrm2, #1C00E2 ), array.push ( c_prcntSpctrm2, #1E00E0 ), array.push ( c_prcntSpctrm2, #2100DD ), array.push ( c_prcntSpctrm2, #2300DB ), array.push ( c_prcntSpctrm2, #2600D8 ),
    array.push ( c_prcntSpctrm2, #2800D6 ), array.push ( c_prcntSpctrm2, #2B00D3 ), array.push ( c_prcntSpctrm2, #2D00D1 ), array.push ( c_prcntSpctrm2, #3000CE ), array.push ( c_prcntSpctrm2, #3300CC ),
    array.push ( c_prcntSpctrm2, #3500C9 ), array.push ( c_prcntSpctrm2, #3800C6 ), array.push ( c_prcntSpctrm2, #3A00C4 ), array.push ( c_prcntSpctrm2, #3D00C1 ), array.push ( c_prcntSpctrm2, #3F00BF ),
    array.push ( c_prcntSpctrm2, #4200BC ), array.push ( c_prcntSpctrm2, #4400BA ), array.push ( c_prcntSpctrm2, #4700B7 ), array.push ( c_prcntSpctrm2, #4900B5 ), array.push ( c_prcntSpctrm2, #4C00B2 ),
    array.push ( c_prcntSpctrm2, #4F00AF ), array.push ( c_prcntSpctrm2, #5100AD ), array.push ( c_prcntSpctrm2, #5400AA ), array.push ( c_prcntSpctrm2, #5600A8 ), array.push ( c_prcntSpctrm2, #5900A5 ),
    array.push ( c_prcntSpctrm2, #5B00A3 ), array.push ( c_prcntSpctrm2, #5E00A0 ), array.push ( c_prcntSpctrm2, #60009E ), array.push ( c_prcntSpctrm2, #63009B ), array.push ( c_prcntSpctrm2, #660099 ),
    array.push ( c_prcntSpctrm2, #680096 ), array.push ( c_prcntSpctrm2, #6B0093 ), array.push ( c_prcntSpctrm2, #6D0091 ), array.push ( c_prcntSpctrm2, #70008E ), array.push ( c_prcntSpctrm2, #72008C ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#750089 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #770087 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #7A0084 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #7C0082 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #7F007F ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#82007C ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #84007A ), array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#870077 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #890075 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #8C0072 ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#8E0070 ), array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#91006D ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #93006B ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #960068 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #990066 ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#9B0063 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #9E0060 ), array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#A0005E ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #A3005B ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #A50059 ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#A80056 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #AA0054 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #AD0051 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #AF004F ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #B2004C ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#B50049 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #B70047 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #BA0044 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #BC0042 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #BF003F ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#C1003D ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #C4003A ), array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#C60038 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #C90035 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #CC0033 ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#CE0030 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #D1002D ), array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#D3002B ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #D60028 ), array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#D80026 ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#DB0023 ), array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#DD0021 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #E0001E ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #E2001C ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #E50019 ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#E80016 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #EA0014 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #ED0011 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #EF000F ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #F2000C ),
    array.push ( c_prcntSpctrm2, hide_lava?color.new(color.white,100):#F4000A ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #F70007 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #F90005 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #FC0002 ), array.push ( c_prcntSpctrm2,hide_lava?color.new(color.white,100): #FF0000 )
// ----------------------------------
var string STM = 'Spectrum'
var string SLD = 'Solid'
// var string BGR = 'Blue Green Red'
var string BR  = 'Blue Red'
// ----------------------------------

//===================================
// BBWP INPUTS
//===================================
// ----------------------------------
i_priceSrc      = input.source  ( close, 'Price Source', group='BBWP - BOLLINGER BANDS WITH PERCENTILE', inline='bbwp_0')
i_basisType     = input.string  ( 'SMA', '     Basis Type', options=['SMA', 'EMA', 'VWMA'], group='BBWP - BOLLINGER BANDS WITH PERCENTILE', inline='bbwp_0')
i_bbwpLen       = input.int     ( 13, 'Length     ', minval=1, group='BBWP - BOLLINGER BANDS WITH PERCENTILE', inline='bbwp_1')
i_bbwpLkbk      = input.int     ( 252, '     Lookback ', minval=1, group='BBWP - BOLLINGER BANDS WITH PERCENTILE', inline='bbwp_1')
// ----------------------------------
i_c_bbwpTyped   = input.string  ( STM, 'Color Type  ', options=[STM, SLD], inline='1', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
i_c_spctrmType  = input.string  ( BR, '    Spectrum  ', options=[BR], inline='1', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
i_c_bbwpsolid   = color.new(color.silver,50)
// ----------------------------------
i_ma1On         = input.bool    ( true, '', inline='1', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
i_ma1Type       = input.string  ( 'SMA', 'MA 1 Type   ', options=['SMA', 'EMA', 'VWMA'], inline='1', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
i_ma1Len        = input.int     ( 5, '   MA 1 Length', minval=1, inline='1', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
// ----------------------------------
i_ma2Type       = input.string  ( 'SMA', 'MA 2 Type  ', options=['SMA', 'EMA', 'VWMA'], inline='2', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
i_ma2Len        = input.int     ( 55, '  MA 2 Length  ', minval=1, inline='2', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
i_ma2On         = input.bool    ( true, '', inline='2', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
// ----------------------------------
i_bbwpWidth     = input.int     ( 2, 'Line Width  ', minval=1, maxval=4, inline='3', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
i_alrtsOn       = input.bool    ( true, 'Highlight extreme values', inline='3', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
i_upperLevel    = input.int     ( 98, 'Extreme High', minval=1, inline='3', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
i_lowerLevel    = input.int     ( 2, 'Extreme Low', minval=1, inline='3', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
// ----------------------------------
// hide_lava = input.bool    (true, 'Hide high values', inline='4', group='BBWP - BOLLINGER BANDS WITH PERCENTILE')
// ----------------------------------

//===================================
// BBWP CALCULATIONS & PLOT
//===================================
// ----------------------------------
bbwp        = show_bbwp ? f_bbwp ( i_priceSrc, i_bbwpLen, i_bbwpLkbk, i_basisType ) : na
c_bbwp      = show_bbwp ? f_clrSlct ( bbwp, i_c_bbwpTyped, i_c_spctrmType, i_c_bbwpsolid, c_prcntSpctrm2 ) : na
bbwpMA1     = show_bbwp and i_ma1On ? f_maType ( bbwp, i_ma1Len, i_ma1Type ) : na
bbwpMA2     = show_bbwp and i_ma2On ? f_maType ( bbwp, i_ma2Len, i_ma2Type ) : na
// ----------------------------------
bdf = bbwp/100
bdf_calc = adjust_number + bdf
// ----------------------------------
hiAlrtBar   = i_alrtsOn and bbwp >= i_upperLevel ? bdf_calc : na
loAlrtBar   = i_alrtsOn and bbwp <= i_lowerLevel ? bdf_calc : na
// ----------------------------------
p_bbwp      = plot (show_bbwp ? bdf_calc : na, 'BBWP', c_bbwp, i_bbwpWidth, plot.style_line, editable=true )
// ----------------------------------
p_hiAlrt    = plot ( show_bbwp ? hiAlrtBar : na, 'Extreme Hi', color.new(#cb0101,85), 1, plot.style_columns, histbase=adjust_number, editable=true )
p_loAlrt    = plot ( show_bbwp ? loAlrtBar : na, 'Extreme Lo', color.new(#3000d9,60), 1, plot.style_columns, histbase=adjust_number+1, editable=true )
// ----------------------------------

Overview

Musashi Fractal Dimension v2 optionally displays RSI and BBWP indicators with customizable sources and baselines. Horizontal lines mark key levels including mid line and various thresholds. Users adjust visibility and lengths through inputs in dedicated groups. The script draws these studies in a separate pane below the price chart. No trading signals entry or exit rules are provided and it serves as a pure visual analysis tool for fractal patterns and momentum. Settings primarily control the calculation lengths and toggle options for each study.

Details

Published by

regalouisei on GitHub

Code credit

Musashi-Alchemist, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volatility & bands

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.

Settings

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

SettingTypeDefaultVariable
FDI      booltrueshow_fdi
RSI      boolfalseshow_rsi
BBWPboolfalseshow_bbwp
FDI Source        sourceclosefdi_src
Slow FDI Length   int21fdi_length
Fast FDIs Length 1:int13fdi_length_2
2:int12fdi_length_3
3:int11fdi_length_4
Baseline Length   int21bandLength
Show Ultra-Slow FDIboolfalseultra_show_fdi
     Lengthint34ultra_fdi_length
Show Baselineboolfalseultra_show_fdi_baseline
Show all 40 settings
SettingTypeDefaultVariable
          Lengthint15ultra_bandLength
Primary RSI Periodint9rsiPeriod
Secondary RSI Periodint7second_rsiPeriod
Baseline Length   int21rsibandLength
Pivot Lookback Rightint2lbR
Pivot Lookback Leftint9lbL
Max of Lookback   int120rangeUpper
    Min of Lookbackint1rangeLower
BullishbooltrueplotBull
Bearish       booltrueplotBear
Hidden BullishbooltrueplotHiddenBull
Hidden BearishbooltrueplotHiddenBear
Show LabelsboolfalseshowLabels
Hide high valuesbooltruehide_lava
Price Sourcesourceclosei_priceSrc
     Basis TypestringSMAi_basisType
Length     int13i_bbwpLen
     Lookback int252i_bbwpLkbk
Color Type  stringSTMi_c_bbwpTyped
    Spectrum  stringBRi_c_spctrmType
i_ma1Onbooltruei_ma1On
MA 1 Type   stringSMAi_ma1Type
   MA 1 Lengthint5i_ma1Len
MA 2 Type  stringSMAi_ma2Type
  MA 2 Length  int55i_ma2Len
i_ma2Onbooltruei_ma2On
Line Width  int2i_bbwpWidth
Highlight extreme valuesbooltruei_alrtsOn
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

TTM Squeeze

by Alorse
330 stars

This indicator plots a TTM Squeeze momentum oscillator in a separate pane. It compares a Bollinger Band offset to a Keltner Channel offset and marks the zero line white when the difference is non-negative and black when the bands are inside the channel. A line

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of TTM Squeeze

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
218 stars

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

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