31
//version=5
indicator("Fractal Levels Multi-TF", overlay=true, max_labels_count=500, max_lines_count=500)

// آرایه ضرایب فیبوناچی
factors = array.from(0.0, 0.0625, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 0.9375, 1.0)
numFactors = array.size(factors)

// تابع کمکی برای ایجاد آرایه‌ای از خطوط با تعداد مشخص و تنظیمات اولیه
createLineArray(col) =>
var lineArray = array.new_line(numFactors)
if barstate.isfirst
for i = 0 to numFactors - 1
array.push(lineArray, line.new(x1=bar_index, y1=na, x2=bar_index+1, y2=na, extend=extend.right, color=col, width=1))
lineArray

// ایجاد آرایه خطوط برای هر تایم‌فریم با رنگ دلخواه
dailyLines = createLineArray(color.red)
fourHLines = createLineArray(color.blue)
oneHLines = createLineArray(color.orange)
min30Lines = createLineArray(color.aqua)
min15Lines = createLineArray(color.purple)
min5Lines = createLineArray(color.green)
min3Lines = createLineArray(color.fuchsia)
min1Lines = createLineArray(color.gray)

// یک تابع برای به‌روزرسانی خطوط هر تایم‌فریم بر اساس آخرین فرکتال‌ها
update_tf_levels(tf, lineArray) =>
// گرفتن فرکتال بالا و پایین از تایم‌فریم مورد نظر
fHigh = request.security(syminfo.tickerid, tf, ta.fractal(high, 2, 2), lookahead=barmerge.lookahead_on)
fLow = request.security(syminfo.tickerid, tf, ta.fractal(low, 2, 2), lookahead=barmerge.lookahead_on)
// ذخیره آخرین مقادیر (بدون استفاده از توابع گلوبال، از سویی

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.