✅ کد آپدیت شده با ضخامت خطوط و سایز سیگنالها قابل تنظیم
📦 ویژگیهای جدید:
- امکان تنظیم ضخامت خط RSI
- امکان تنظیم ضخامت خطوط افقی (Overbought/Oversold) برای هر سطح
- امکان تنظیم سایز سیگنالها (خرید/فروش) به صورت جداگانه
📌 کد کامل:
//@version=5
indicator("RSI with Dual Overbought/Oversold Levels", shorttitle="RSI Dual Zones", overlay=false)
// -----------------------------------------------------------------------------
// Customizable User Inputs
// -----------------------------------------------------------------------------
// RSI period length (usually 14)
rsiLength = input.int(14, title="RSI Length", minval=1)
// RSI line color and width
rsiColor = input.color(color.blue, title="RSI Line Color")
rsiLineWidth = input.int(2, title="RSI Line Width", minval=1, maxval=10)
// First set of OB/OS levels (e.g., 70 / 30)
obLevel1 = input.float(70.0, title="Overbought Level 1", minval=0, maxval=100)
osLevel1 = input.float(30.0, title="Oversold Level 1", minval=0, maxval=100)
// Colors for Level 1 lines and zones
obLineColor1 = input.color(color.red, title="Overbought Line Color 1")
osLineColor1 = input.color(color.green, title="Oversold Line Color 1")
obZoneColor1 = input.color(color.red, title="Overbought Zone Color 1")
osZoneColor1 = input.color(color.green, title="Oversold Zone Color 1")
// Transparency for Level 1 zones
obZoneAlpha1 = input.int(80, title="Overbought Zone Transparency 1", minval=0, maxval=100)
osZoneAlpha1 = input.int(85, title="Oversold Zone Transparency 1", minval=0, maxval=100)
// Line style for Level 1
obLineStyle1 = input.string("dashed", title="Overbought Line Style 1", options=["solid", "dashed", "dotted"])
osLineStyle1 = input.string("dotted", title="Oversold Line Style 1", options=["solid", "dashed", "dotted"])
// Line thickness for Level 1
obLineThickness1 = input.int(1, title="Overbought Line Thickness 1", minval=1, maxval=5)
osLineThickness1 = input.int(1, title="Oversold Line Thickness 1", minval=1, maxval=5)
// Second set of OB/OS levels (e.g., 80 / 20)
obLevel2 = input.float(80.0, title="Overbought Level 2", minval=0, maxval=100)
osLevel2 = input.float(20.0, title="Oversold Level 2", minval=0, maxval=100)
// Colors for Level 2 lines and zones
obLineColor2 = input.color(color.orange, title="Overbought Line Color 2")
osLineColor2 = input.color(color.lime, title="Oversold Line Color 2")
obZoneColor2 = input.color(color.orange, title="Overbought Zone Color 2")
osZoneColor2 = input.color(color.lime, title="Oversold Zone Color 2")
// Transparency for Level 2 zones
obZoneAlpha2 = input.int(80, title="Overbought Zone Transparency 2", minval=0, maxval=100)
osZoneAlpha2 = input.int(85, title="Oversold Zone Transparency 2", minval=0, maxval=100)
// Line style for Level 2
obLineStyle2 = input.string("solid", title="Overbought Line Style 2", options=["solid", "dashed", "dotted"])
osLineStyle2 = input.string("dashed", title="Oversold Line Style 2", options=["solid", "dashed", "dotted"])
// Line thickness for Level 2
obLineThickness2 = input.int(1, title="Overbought Line Thickness 2", minval=1, maxval=5)
osLineThickness2 = input.int(1, title="Oversold Line Thickness 2", minval=1, maxval=5)
// Signal colors
buySignalColor1 = input.color(color.green, title="Buy Signal Color (OS1)")
buySignalColor2 = input.color(color.lime, title="Buy Signal Color (OS2)")
sellSignalColor1 = input.color(color.red, title="Sell Signal Color (OB1)")
sellSignalColor2 = input.color(color.orange, title="Sell Signal Color (OB2)")
// Signal sizes
buySignalSize1 = input.string("small", title="Buy Signal Size (OS1)", options=["tiny", "small", "normal", "large"])
buySignalSize2 = input.string("small", title="Buy Signal Size (OS2)", options=["tiny", "small", "normal", "large"])
sellSignalSize1 = input.string("small", title="Sell Signal Size (OB1)", options=["tiny", "small", "normal", "large"])
sellSignalSize2 = input.string("small", title="Sell Signal Size (OB2)", options=["tiny", "small", "normal", "large"])
// -----------------------------------------------------------------------------
// Helper Functions
// -----------------------------------------------------------------------------
// Map string to Pine Script size
sizeFromString(s) =>
s == "tiny" ? size.tiny :
s == "small" ? size.small :
s == "normal" ? size.normal :
size.large
// Map string to line style
lineStyleFromString(s) =>
s == "solid" ? hline.style_solid : s == "dashed" ? hline.style_dashed : hline.style_dotted
// -----------------------------------------------------------------------------
// Indicator Calculations
// -----------------------------------------------------------------------------
rsiValue = ta.rsi(close, rsiLength)
// -----------------------------------------------------------------------------
// Plotting the Indicator and Levels
// -----------------------------------------------------------------------------
plot(rsiValue, "RSI", color=rsiColor, linewidth=rsiLineWidth)
// Plot horizontal lines for Overbought/Oversold levels (Set 1)
hline(obLevel1, "Overbought Level 1", color=obLineColor1, linestyle=lineStyleFromString(obLineStyle1), linewidth=obLineThickness1)
hline(osLevel1, "Oversold Level 1", color=osLineColor1, linestyle=lineStyleFromString(osLineStyle1), linewidth=osLineThickness1)
// Plot horizontal lines for Overbought/Oversold levels (Set 2)
hline(obLevel2, "Overbought Level 2", color=obLineColor2, linestyle=lineStyleFromString(obLineStyle2), linewidth=obLineThickness2)
hline(osLevel2, "Oversold Level 2", color=osLineColor2, linestyle=lineStyleFromString(osLineStyle2), linewidth=osLineThickness2)
// Mid-line
hline(50, "Mid-Line (50)", color=color.gray, linestyle=hline.style_dashed)
// -----------------------------------------------------------------------------
// Background Coloring for Zones
// -----------------------------------------------------------------------------
bgcolor(rsiValue > obLevel2 ? color.new(obZoneColor2, obZoneAlpha2) : na, title="OB Zone 2")
bgcolor(rsiValue <= obLevel2 and rsiValue > obLevel1 ? color.new(obZoneColor1, obZoneAlpha1) : na, title="OB Zone 1")
bgcolor(rsiValue < osLevel2 ? color.new(osZoneColor2, osZoneAlpha2) : na, title="OS Zone 2")
bgcolor(rsiValue >= osLevel2 and rsiValue < osLevel1 ? color.new(osZoneColor1, osZoneAlpha1) : na, title="OS Zone 1")
// -----------------------------------------------------------------------------
// Generating Buy/Sell Signals (Crossovers)
// -----------------------------------------------------------------------------
crossUpOS1 = ta.crossover(rsiValue, osLevel1)
crossUpOS2 = ta.crossover(rsiValue, osLevel2)
crossDownOB1 = ta.crossunder(rsiValue, obLevel1)
crossDownOB2 = ta.crossunder(rsiValue, obLevel2)
// -----------------------------------------------------------------------------
// Plotting Shapes for Signals on the Main Chart (WITH CUSTOM SIZES)
// -----------------------------------------------------------------------------
plotshape(crossUpOS1, title="Buy Signal (OS1)", location=location.belowbar, color=buySignalColor1, style=shape.triangleup, size=sizeFromString(buySignalSize1), text="Buy1")
plotshape(crossUpOS2, title="Buy Signal (OS2)", location=location.belowbar, color=buySignalColor2, style=shape.triangleup, size=sizeFromString(buySignalSize2), text="Buy2")
plotshape(crossDownOB1, title="Sell Signal (OB1)", location=location.abovebar, color=sellSignalColor1, style=shape.triangledown, size=sizeFromString(sellSignalSize1), text="Sell1")
plotshape(crossDownOB2, title="Sell Signal (OB2)", location=location.abovebar, color=sellSignalColor2, style=shape.triangledown, size=sizeFromString(sellSignalSize2), text="Sell2")
// -----------------------------------------------------------------------------
// Defining Alert Conditions for TradingView
// -----------------------------------------------------------------------------
alertcondition(crossUpOS1 or crossUpOS2, title="RSI Buy Alert", message="RSI crossed above Oversold level.")
alertcondition(crossDownOB1 or crossDownOB2, title="RSI Sell Alert", message="RSI crossed below Overbought level.")
📌 تغییرات اعمال شده:
✅ ضخامت خطوط RSI و افقی:
rsiLineWidth = input.int(2, title="RSI Line Width", minval=1, maxval=10)
obLineThickness1 = input.int(1, title="Overbought Line Thickness 1", minval=1, maxval=5)
osLineThickness1 = input.int(1, title="Oversold Line Thickness 1", minval=1, maxval=5)
✅ استفاده از ضخامت در hline:
hline(obLevel1, "Overbought Level 1", color=obLineColor1, linestyle=lineStyleFromString(obLineStyle1), linewidth=obLineThickness1)
✅ سایز سیگنالها:
buySignalSize1 = input.string("small", title="Buy Signal Size (OS1)", options=["tiny", "small", "normal", "large"])
✅ استفاده از سایز در plotshape:
plotshape(crossUpOS1, ..., size=sizeFromString(buySignalSize1))
🎨 پیشنهادات:
| عنصر | پیشنهاد |
|---|
| RSI Line Width | 2 یا 3 |
| OB Line Thickness | 1 یا 2 |
| OS Line Thickness | 1 یا 2 |
| Buy Signal Size (OS1) | Small |
| Buy Signal Size (OS2) | Normal |
| Sell Signal Size (OB1) | Small |
| Sell Signal Size (OB2) | Normal |
💡 نکته:
- تمامی تنظیمات به صورت جداگانه و کاملاً شخصیسازیشده امکانپذیر است.
- میتوانید سیگنالهای ضعیفتر را با سایز کوچکتر و سیگنالهای قویتر را با سایز بزرگتر نمایش دهید.
اگر میخواهید رنگهای پیشفرض یا تنظیمات دیگر را هم تغییر دهید، فقط بگویید! 😊