can you help edit this script, i don’t know how to edit a script i only use ai, but my problem is i want the bar that created an inside bar and it’s preceding bar, if it not crossed it’s high or low it should not show any fractals.
//@version=5
indicator(“Scooby fractal”, shorttitle=”SCOOBY Fractal”, overlay=true, max_boxes_count=500, max_lines_count=500, max_labels_count=500)
// Inputs for Swing Points
swingSizeR = input.int(1, ‘Bars Right-Left’, inline=’brl’)
swingSizeL = input.int(1, ‘-‘, inline=’brl’)
// Line style input
lineStyleOpt = input.string(title=”Line Style”, defval=”Dotted”, options=[“Solid”, “Dotted”, “Dashed”])
// Line width input
lineWidth = input.int(title=”Line Width”, defval=1, minval=1, maxval=10)
// Line color inputs
downFractalColor = input.color(title=”Down Fractal Line Color”, defval=color.green)
upFractalColor = input.color(title=”Up Fractal Line Color”, defval=color.red)
// Function to get line style
getLineStyle(style) =>
switch style
"Solid" => line.style_solid
"Dotted" => line.style_dotted
"Dashed" => line.style_dashed
lineStyle = getLineStyle(lineStyleOpt)
// Pivot calculations using swing points
pivHi = ta.pivothigh(high, swingSizeL, swingSizeR)
pivLo = ta.pivotlow(low, swingSizeL, swingSizeR)
// Variables to store fractal lines
var levelLines = array.new_line()
var levelPrices = array.new_float()
var levelColors = array.new_color()
var levelCrossed = array.new_bool()
// Plot the pivot points as shapes on the chart with color matching the line color
plotshape(series=not na(pivHi), style=shape.triangledown, location=location.abovebar, offset=-swingSizeR, color=downFractalColor, transp=25)
plotshape(series=not na(pivLo), style=shape.triangleup, location=location.belowbar, offset=-swingSizeR, color=upFractalColor, transp=25)
// Function to create and store lines
createLine(fractalLevel, fractalBarIndex, color) =>
ln = line.new(x1=fractalBarIndex, y1=fractalLevel, x2=bar_index, y2=fractalLevel, color=color.new(color, 100), width=lineWidth, style=lineStyle) // Hide line initially
array.push(levelLines, ln)
array.push(levelPrices, fractalLevel)
array.push(levelColors, color)
array.push(levelCrossed, false)
// Create lines for new swing points
if not na(pivHi)
createLine(pivHi, bar_index[swingSizeR], downFractalColor)
if not na(pivLo)
createLine(pivLo, bar_index[swingSizeR], upFractalColor)
// Extend lines once they are crossed
size = array.size(levelLines)
if size > 0
for i = 0 to size - 1
ln = array.get(levelLines, i)
level = array.get(levelPrices, i)
crossed = array.get(levelCrossed, i)
ln_color = array.get(levelColors, i)
if not crossed and high >= level and low <= level
line.set_x2(ln, bar_index)
line.set_color(ln, ln_color)
array.set(levelCrossed, i, true)
else if not crossed
line.set_x2(ln, bar_index)
// Deleting the oldest lines if array is too big
maxLines = 500
if array.size(levelLines) >= maxLines
int i = 0
while array.size(levelLines) >= maxLines
ln = array.get(levelLines, i)
line.delete(ln)
array.remove(levelLines, i)
array.remove(levelPrices, i)
array.remove(levelColors, i)
array.remove(levelCrossed, i)
i += 1
indicator(“Scooby fractal”, shorttitle=”SCOOBY Fractal”, overlay=true, max_boxes_count=500, max_lines_count=500, max_labels_count=500)
// Inputs for Swing Points
swingSizeR = input.int(1, ‘Bars Right-Left’, inline=’brl’)
swingSizeL = input.int(1, ‘-‘, inline=’brl’)
// Line style input
lineStyleOpt = input.string(title=”Line Style”, defval=”Dotted”, options=[“Solid”, “Dotted”, “Dashed”])
// Line width input
lineWidth = input.int(title=”Line Width”, defval=1, minval=1, maxval=10)
// Line color inputs
downFractalColor = input.color(title=”Down Fractal Line Color”, defval=color.green)
upFractalColor = input.color(title=”Up Fractal Line Color”, defval=color.red)
// Function to get line style
getLineStyle(style) =>
switch style
"Solid" => line.style_solid
"Dotted" => line.style_dotted
"Dashed" => line.style_dashed
lineStyle = getLineStyle(lineStyleOpt)
// Pivot calculations using swing points
pivHi = ta.pivothigh(high, swingSizeL, swingSizeR)
pivLo = ta.pivotlow(low, swingSizeL, swingSizeR)
// Variables to store fractal lines
var levelLines = array.new_line()
var levelPrices = array.new_float()
var levelColors = array.new_color()
var levelCrossed = array.new_bool()
// Plot the pivot points as shapes on the chart with color matching the line color
plotshape(series=not na(pivHi), style=shape.triangledown, location=location.abovebar, offset=-swingSizeR, color=downFractalColor, transp=25)
plotshape(series=not na(pivLo), style=shape.triangleup, location=location.belowbar, offset=-swingSizeR, color=upFractalColor, transp=25)
// Function to create and store lines
createLine(fractalLevel, fractalBarIndex, color) =>
ln = line.new(x1=fractalBarIndex, y1=fractalLevel, x2=bar_index, y2=fractalLevel, color=color.new(color, 100), width=lineWidth, style=lineStyle) // Hide line initially
array.push(levelLines, ln)
array.push(levelPrices, fractalLevel)
array.push(levelColors, color)
array.push(levelCrossed, false)
// Create lines for new swing points
if not na(pivHi)
createLine(pivHi, bar_index[swingSizeR], downFractalColor)
if not na(pivLo)
createLine(pivLo, bar_index[swingSizeR], upFractalColor)
// Extend lines once they are crossed
size = array.size(levelLines)
if size > 0
for i = 0 to size - 1
ln = array.get(levelLines, i)
level = array.get(levelPrices, i)
crossed = array.get(levelCrossed, i)
ln_color = array.get(levelColors, i)
if not crossed and high >= level and low <= level
line.set_x2(ln, bar_index)
line.set_color(ln, ln_color)
array.set(levelCrossed, i, true)
else if not crossed
line.set_x2(ln, bar_index)
// Deleting the oldest lines if array is too big
maxLines = 500
if array.size(levelLines) >= maxLines
int i = 0
while array.size(levelLines) >= maxLines
ln = array.get(levelLines, i)
line.delete(ln)
array.remove(levelLines, i)
array.remove(levelPrices, i)
array.remove(levelColors, i)
array.remove(levelCrossed, i)
i += 1
Crypto Mark is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1