The Pine version of this script is unspecified, so it will compile as Pine v1. To use…
- User
The Pine version of this script is unspecified, so it will compile as Pine v1. To use another version of Pine, add '//@version={versionNumber}' to the top of the script. E.g., '//@version=5' for Pine v5.
Assistant
بله، درست است. برای اسکریپت TradingView با زبان Pine، باید نسخه را مشخص کنیم. اینجا یک اسکریپت Pine v5 برای نمایش سطوح حمایت و مقاومت ارائه میکنم:
//@version=5 indicator("Support & Resistance Levels", overlay=true) // تنظیمات lookback = input.int(20, "Lookback Period") threshold = input.float(0.02, "Price Threshold", minval=0.001, maxval=0.1, step=0.001) show_labels = input.bool(true, "Show Labels") strong_level_touches = input.int(3, "Strong Level Min Touches") // توابع کمکی pivotlow = ta.pivotlow(low, lookback, lookback) pivothigh = ta.pivothigh(high, lookback, lookback) // آرایههای ذخیره سطوح var float[] support_levels = array.new_float(0) var float[] resistance_levels = array.new_float(0) var int[] support_touches = array.new_int(0) var int[] resistance_touches = array.new_int(0) // بررسی و اضافه کردن سطوح جدید if not na(pivotlow) newLevel = true for i = 0 to array.size(support_levels) - 1 level = array.get(support_levels, i) if math.abs(level - pivotlow) / level < threshold newLevel := false array.set(support_touches, i, array.get(support_touches, i) + 1) break if newLevel array.push(support_levels, pivotlow) array.push(support_touches, 1) if not na(pivothigh) newLevel = true for i = 0 to array.size(resistance_levels) - 1 level = array.get(resistance_levels, i) if math.abs(level - pivothigh) / level < threshold newLevel := false array.set(resistance_touches, i, array.get(resistance_touches, i) + 1) break if newLevel array.push(resistance_levels, pivothigh) array.push(resistance_touches, 1) // رسم سطوح draw_level(price, touches, isSupport) => var line level_line = na var label level_label = na if not na(price) color = isSupport ? (touches >= strong_level_touches ? color.new(color.green, 0) : color.new(color.green, 50)) : (touches >= strong_level_touches ? color.new(color.red, 0) : color.new(color.red, 50)) style = touches >= strong_level_touches ? line.style_solid : line.style_dashed width = touches >= strong_level_touches ? 2 : 1 if not na(level_line) line.delete(level_line) if not na(level_label) and show_labels label.delete(level_label) level_line := line.new(x1=bar_index - lookback, y1=price, x2=bar_index + 5, y2=price, color=color, style=style, width=width, extend=extend.right) if show_labels level_label := label.new(x=bar_index + 10, y=price, text=isSupport ? "S (" + str.tostring(touches) + ")" : "R (" + str.tostring(touches) + ")", color=color, style=label.style_label_left, textcolor=color.white) // رسم همه سطوح if barstate.islast for i = 0 to array.size(support_levels) - 1 level = array.get(support_levels, i) touches = array.get(support_touches, i) draw_level(level, touches, true) for i = 0 to array.size(resistance_levels) - 1 level = array.get(resistance_levels, i) touches = array.get(resistance_touches, i) draw_level(level, touches, false) // نمایش اطلاعات اضافی var table info = table.new(position.top_right, 2, 2) if barstate.islast strong_supports = 0 strong_resistances = 0 for i = 0 to array.size(support_touches) - 1 if array.get(support_touches, i) >= strong_level_touches strong_supports += 1 for i = 0 to array.size(resistance_touches) - 1 if array.get(resistance_touches, i) >= strong_level_touches strong_resistances += 1 table.cell(info, 0, 0, "Strong Supports", bgcolor=color.new(color.green, 90)) table.cell(info, 1, 0, str.tostring(strong_supports), bgcolor=color.new(color.green, 90)) table.cell(info, 0, 1, "Strong Resistances", bgcolor=color.new(color.red, 90)) table.cell(info, 1, 1, str.tostring(strong_resistances), bgcolor=color.new(color.red, 90)) // اضافه کردن میانگین متحرکها ma20 = ta.sma(close, 20) ma50 = ta.sma(close, 50) plot(ma20, "MA20", color=color.new(color.blue, 0), linewidth=1) plot(ma50, "MA50", color=color.new(color.orange, 0), linewidth=1) // نمایش سیگنالهای احتمالی plotshape(ta.crossover(close, ma20), "Cross Above MA20", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small) plotshape(ta.crossunder(close, ma20), "Cross Below MA20", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)ویژگیهای این اسکریپت:
-
تشخیص خودکار سطوح:
- استفاده از Pivot Points برای شناسایی سطوح
- گروهبندی سطوح نزدیک به هم
-
رنگبندی هوشمند:
- سطوح قوی: رنگ پررنگ و خط ممتد
- سطوح ضعیف: رنگ کمرنگ و خط خطچین
-
نمایش اطلاعات تکمیلی:
- تعداد برخوردها با هر سطح
- جدول خلاصه سطوح قوی
-
میانگینهای متحرک:
- MA20 و MA50
- نمایش سیگنالهای تقاطع
-
قابلیت تنظیم:
- دوره نگاه به عقب
- آستانه قیمت برای گروهبندی
- حداقل تعداد برخورد برای سطوح قوی
برای استفاده:
- این کد را در TradingView در بخش Pine Editor کپی کنید
- روی "Add to Chart" کلیک کنید
- تنظیمات را طبق نیاز خود تغییر دهید
این اسکریپت سطوح حمایت و مقاومت را به صورت پویا محاسبه و نمایش میدهد و با هر بار آپدیت قیمت، سطوح را بهروز میکند.
-
- User
Mismatched input 'end of line without line continuation' expecting ')'
Assistant
اصلاح شده اسکریپت برای رفع خطای سینتکس:
//@version=5 indicator("Support & Resistance Levels", overlay=true) // تنظیمات lookback = input.int(20, "Lookback Period") threshold = input.float(0.02, "Price Threshold", minval=0.001, maxval=0.1, step=0.001) show_labels = input.bool(true, "Show Labels") strong_level_touches = input.int(3, "Strong Level Min Touches") // محاسبه نقاط پیوت pivotlow = ta.pivotlow(low, lookback, lookback) pivothigh = ta.pivothigh(high, lookback, lookback) // آرایههای ذخیره سطوح var support_levels = array.new_float(0) var resistance_levels = array.new_float(0) var support_touches = array.new_int(0) var resistance_touches = array.new_int(0) // تابع بررسی و اضافه کردن سطح جدید f_add_level(level, levels, touches, is_support) => if not na(level) newLevel = true for i = 0 to array.size(levels) - 1 current_level = array.get(levels, i) if math.abs(current_level - level) / current_level < threshold newLevel := false array.set(touches, i, array.get(touches, i) + 1) break if newLevel array.push(levels, level) array.push(touches, 1) // اضافه کردن سطوح جدید f_add_level(pivotlow, support_levels, support_touches, true) f_add_level(pivothigh, resistance_levels, resistance_touches, false) // تابع رسم سطح f_draw_level(price, touches, is_support) => if not na(price) color = is_support ? (touches >= strong_level_touches ? color.green : color.new(color.green, 50)) : (touches >= strong_level_touches ? color.red : color.new(color.red, 50)) style = touches >= strong_level_touches ? line.style_solid : line.style_dashed width = touches >= strong_level_touches ? 2 : 1 line.new(bar_index[lookback], price, bar_index, price, color=color, style=style, width=width, extend=extend.right) if show_labels label.new(bar_index, price, text=is_support ? "S" + str.tostring(touches) : "R" + str.tostring(touches), color=color, style=label.style_label_left, textcolor=color.white) // رسم سطوح در آخرین بار if barstate.islast for i = 0 to array.size(support_levels) - 1 f_draw_level(array.get(support_levels, i), array.get(support_touches, i), true) for i = 0 to array.size(resistance_levels) - 1 f_draw_level(array.get(resistance_levels, i), array.get(resistance_touches, i), false) // میانگینهای متحرک ma20 = ta.sma(close, 20) ma50 = ta.sma(close, 50) // رسم میانگینهای متحرک plot(ma20, "MA20", color=color.blue, linewidth=1) plot(ma50, "MA50", color=color.orange, linewidth=1) // نمایش سیگنالهای تقاطع plotshape(ta.crossover(close, ma20), "Cross Above MA20", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small) plotshape(ta.crossunder(close, ma20), "Cross Below MA20", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small) // نمایش اطلاعات در جدول var tbl = table.new(position.top_right, 2, 2, bgcolor=color.new(color.black, 90)) if barstate.islast strong_s = 0 strong_r = 0 for i = 0 to array.size(support_touches) - 1 if array.get(support_touches, i) >= strong_level_touches strong_s += 1 for i = 0 to array.size(resistance_touches) - 1 if array.get(resistance_touches, i) >= strong_level_touches strong_r += 1 table.cell(tbl, 0, 0, "Strong S", bgcolor=color.new(color.green, 90)) table.cell(tbl, 1, 0, str.tostring(strong_s), bgcolor=color.new(color.green, 90)) table.cell(tbl, 0, 1, "Strong R", bgcolor=color.new(color.red, 90)) table.cell(tbl, 1, 1, str.tostring(strong_r), bgcolor=color.new(color.red, 90))تغییرات اصلی:
- اصلاح ساختار توابع و پرانتزگذاری
- سادهسازی برخی توابع
- بهبود مدیریت حافظه با استفاده از توابع کمکی
- اصلاح سینتکس برای سازگاری با Pine v5
برای استفاده:
- کد را در Pine Editor کپی کنید
- دکمه "Add to Chart" را بزنید
- تنظیمات را از طریق Settings تغییر دهید
این اسکریپت:
- سطوح حمایت و مقاومت را نشان میدهد
- سطوح قوی را با رنگ پررنگتر مشخص میکند
- میانگینهای متحرک و سیگنالهای آنها را نمایش میدهد
- تعداد سطوح قوی را در یک جدول نشان میدهد
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.