Pinescript, ni fractal in inside bar

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

New contributor

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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật