کد را کامل بنویس
- User
کد را کامل بنویس
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
کد را کامل بنویس
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
//@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=5)
// 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"])
// 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"])
// 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", "huge"])
buySignalSize2 = input.string("small", title="Buy Signal Size (OS2)", options=["tiny", "small", "normal", "large", "huge"])
sellSignalSize1 = input.string("small", title="Sell Signal Size (OB1)", options=["tiny", "small", "normal", "large", "huge"])
sellSignalSize2 = input.string("small", title="Sell Signal Size (OB2)", options=["tiny", "small", "normal", "large", "huge"])
// -----------------------------------------------------------------------------
// Indicator Calculations
// -----------------------------------------------------------------------------
rsiValue = ta.rsi(close, rsiLength)
// -----------------------------------------------------------------------------
// Helper functions
// -----------------------------------------------------------------------------
lineStyleFromString(s) =>
s == "solid" ? hline.style_solid : s == "dashed" ? hline.style_dashed : hline.style_dotted
sizeFromString(s) =>
s == "tiny" ? size.tiny : s == "small" ? size.small : s == "normal" ? size.normal : s == "large" ? size.large : size.huge
// -----------------------------------------------------------------------------
// Plotting the Indicator and Levels
// -----------------------------------------------------------------------------
plot(rsiValue, "RSI", color=rsiColor, linewidth=rsiLineWidth)
hline(obLevel1, "Overbought Level 1", color=obLineColor1, linestyle=lineStyleFromString(obLineStyle1))
hline(osLevel1, "Oversold Level 1", color=osLineColor1, linestyle=lineStyleFromString(osLineStyle1))
hline(obLevel2, "Overbought Level 2", color=obLineColor2, linestyle=lineStyleFromString(obLineStyle2))
hline(osLevel2, "Oversold Level 2", color=osLineColor2, linestyle=lineStyleFromString(osLineStyle2))
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
// -----------------------------------------------------------------------------
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.")
rsiLineWidth = input.int(2, title="RSI Line Width", minval=1, maxval=5)
plot(rsiValue, "RSI", color=rsiColor, linewidth=rsiLineWidth)
buySignalSize1 = input.string("small", title="Buy Signal Size (OS1)", options=["tiny", "small", "normal", "large", "huge"])
sizeFromString(s) =>
s == "tiny" ? size.tiny : s == "small" ? size.small : s == "normal" ? size.normal : s == "large" ? size.large : size.huge
| قابلیت | توضیحات |
|---|---|
| رنگ خط RSI | قابل تنظیم |
| ضخامت خط RSI | از 1 تا 5 |
| دو سطح Overbought | با رنگ، استایل و شفافیت جداگانه |
| دو سطح Oversold | با رنگ، استایل و شفافیت جداگانه |
| سیگنالهای خرید/فروش | با رنگ و سایز قابل تنظیم |
| شفافیت مناطق | از 0 تا 100 |
| استایل خطوط | Solid, Dashed, Dotted |
متاسفانه Pine Script اجازه تنظیم ضخامت خطوط hline را نمیدهد، بنابراین فقط ضخامت خط RSI قابل تنظیم است.
اگر نیاز به تغییرات بیشتری دارید، حتماً بفرمایید! 😊