my problem is that i can’t get rid of the fractals within the mother candle’s ranges, there are always some still appearing. because I would like that as long as the mother candle is not crossed, its range will be no fractals.
//@version=5 indicator(‘Scooby Fractal with Inside Bar Setup’, 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_dashedlineStyle = 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)// Inside Bar Setup var inside_bar = array.new_int(0) var inside_bar_high = array.new_float(0) var inside_bar_low = array.new_float(0) var motherCandleHigh = 0.0 var motherCandleLow = 0.0isInside() => previousBar = 1 isInsidePattern = high < high[previousBar] and low > low[previousBar] isInsidePatternnewDay = ta.change(time(‘D’))if newDay array.clear(inside_bar) array.clear(inside_bar_high) array.clear(inside_bar_low)if isInside() and array.size(inside_bar) <= 0 array.push(inside_bar, bar_index) array.push(inside_bar_high, high[1]) array.push(inside_bar_low, low[1])if barstate.islast and array.size(inside_bar) > 0 motherCandleHigh := array.get(inside_bar_high, 0) motherCandleLow := array.get(inside_bar_low, 0)// 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) and (motherCandleHigh == 0 or (pivHi > motherCandleHigh or pivHi < motherCandleLow)) createLine(pivHi, bar_index[swingSizeR], downFractalColor)if not na(pivLo) and (motherCandleHigh == 0 or (pivLo > motherCandleHigh or pivLo < motherCandleLow)) 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.