커뮤니티
지표 부탁 드립니다
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Uncle_the_shooter
//@version=6
indicator('Pivot Oscillator', overlay=false, max_lines_count=500, max_labels_count=500, precision=2)
// PIVOT SETTINGS (user inputs)
lenSwing = input.int(5, 'Pivot Length', minval=1, group='Pivot Settings')
pivotLevel = input.float(0.5, 'Pivot Level', minval=0.0, maxval=1.0, step=0.01, group='Pivot Settings')
lookback = input.int(5, 'Pivot Lookback', minval=1, group='Pivot Settings')
// ATR SCALING
atrLen = input.int(14, 'ATR Length', minval=1, group='ATR Settings')
multUp = input.float(15.0, 'ATR Multiplier Up', minval=0.1, group='ATR Settings')
multDown = input.float(15.0, 'ATR Multiplier Down', minval=0.1, group='ATR Settings')
// THRESHOLD LEVELS
obLevel = input.float(70, 'Overbought Level', minval=51, maxval=99, group='Threshold Levels')
osLevel = input.float(30, 'Oversold Level', minval=1, maxval=49, group='Threshold Levels')
maOverbought = input.float(60, 'MA Overbought Threshold', minval=51, maxval=99, group='Threshold Levels')
maOversold = input.float(40, 'MA Oversold Threshold', minval=1, maxval=49, group='Threshold Levels')
// SIGNAL SETTINGS
signalLength = input.int(14, 'SMA Length for Signal', group='Signal Settings')
extraSmooth = input.int(10, "SMA Smoothing", minval=1, group='Signal Settings')
// COLORS
bullColor = input.color(color.rgb(22,193,67), 'Bullish Color', group='Style Settings')
bearColor = input.color(color.rgb(229,11,11), 'Bearish Color', group='Style Settings')
signalColorBull = input.color(color.rgb(22,193,67), 'Signal SMA Bullish', group='Style Settings')
signalColorBear = input.color(color.rgb(229,11,11), 'Signal SMA Bearish', group='Style Settings')
obColor = input.color(color.red, 'Overbought Line Color', group='Style Settings')
osColor = input.color(color.green, 'Oversold Line Color', group='Style Settings')
midLineColor = input.color(color.gray, 'Midline 50 Color', group='Style Settings') // <--- nowy input
textColor = input.color(color.white, 'Text Color', group='Style Settings')
// GRADIENT SETTINGS
showOverboughtGradient = input.bool(true, 'Show Overbought Gradient', group='Gradient Settings')
showOversoldGradient = input.bool(true, 'Show Oversold Gradient', group='Gradient Settings')
showOscillatorGradient = input.bool(true, 'Show Oscillator Gradient', group='Gradient Settings')
showMaGradient = input.bool(true, 'Show Moving Average Gradient', group='Gradient Settings')
fillEnabled = input.bool(true, 'Enable Gradient Fill', group='Gradient Settings')
fillTransparency = input.int(75, 'Gradient Fill Transparency', minval=0, maxval=100, group='Gradient Settings')
bandTransparency = input.int(50, 'Band/Label Gradient Transparency', minval=0, maxval=100, group='Gradient Settings')
// INTERNAL VARIABLES
rangeUpper = 60
rangeLower = 5
var int gradientTransparency = 85
// PIVOTS CALCULATION
ph = ta.pivothigh(high, lenSwing, lenSwing)
pl = ta.pivotlow(low, lenSwing, lenSwing)
var float[] phArray = array.new_float()
var float[] plArray = array.new_float()
if not na(ph)
array.push(phArray, ph)
if array.size(phArray) > lookback
array.shift(phArray)
if not na(pl)
array.push(plArray, pl)
if array.size(plArray) > lookback
array.shift(plArray)
avgPH = array.size(phArray) > 0 ? array.avg(phArray) : na
avgPL = array.size(plArray) > 0 ? array.avg(plArray) : na
pivotLine = not na(avgPH) and not na(avgPL) ? avgPL + (avgPH - avgPL) * pivotLevel : na
osc_raw = close - nz(pivotLine)
// ATR SCALING
atr = ta.atr(atrLen)
atr_safe = atr > 0 ? atr : 1
upper_bound = atr_safe * multUp
lower_bound = atr_safe * multDown
float osc_scaled = 50.0
if osc_raw > 0
osc_scaled := 50.0 + 50.0 * (osc_raw / upper_bound)
else if osc_raw < 0
osc_scaled := 50.0 + 50.0 * (osc_raw / lower_bound)
else
osc_scaled := 50.0
osc_scaled := math.max(1.0, math.min(100.0, osc_scaled))
oscSignal = ta.sma(osc_scaled, signalLength)
// DYNAMIC COLORS FOR OB/OS
ob_gradient_color = oscSignal >= maOverbought ? obColor : color.gray
os_gradient_color = oscSignal <= maOversold ? osColor : color.gray
// PLOTTING
hline(obLevel, 'Overbought', color=obColor, linestyle=hline.style_dashed, linewidth=1)
plot(showOverboughtGradient ? obLevel : na, 'OB Gradient', color=color.new(ob_gradient_color, bandTransparency), linewidth=8, editable=false)
hline(osLevel, 'Oversold', color=osColor, linestyle=hline.style_dashed, linewidth=1)
plot(showOversoldGradient ? osLevel : na, 'OS Gradient', color=color.new(os_gradient_color, bandTransparency), linewidth=8, editable=false)
// MIDLINE 50
hline(50, 'Midline 50', color=midLineColor, linestyle=hline.style_dashed, linewidth=1)
hline(1, 'Min', color=color.new(color.gray, 80), linestyle=hline.style_dotted)
hline(100, 'Max', color=color.new(color.gray, 80), linestyle=hline.style_dotted)
lineColor = osc_raw > 0 ? bullColor : bearColor
pOsc = plot(osc_scaled, 'Oscillator 1–100', color=lineColor, linewidth=2)
plot(showOscillatorGradient ? osc_scaled : na, 'Osc Gradient', color=color.new(lineColor, gradientTransparency), linewidth=10)
// SMA SMOOTHED + DYNAMIC COLOR + GRADIENT
smoothSignal = ta.sma(oscSignal, extraSmooth)
dynSignalColor =
smoothSignal > smoothSignal[1] ? signalColorBull :
smoothSignal < smoothSignal[1] ? signalColorBear :
color.gray
// SMA PLOT
pSignal = plot(showMaGradient ? smoothSignal : smoothSignal, "Signal SMA", dynSignalColor, 2)
// SMA GRADIENT – 3 layers
plot(showMaGradient ? smoothSignal : na, "", color.new(dynSignalColor, 60), 5)
plot(showMaGradient ? smoothSignal : na, "", color.new(dynSignalColor, 35), 3)
plot(showMaGradient ? smoothSignal : na, "", color.new(dynSignalColor, 0), 1)
// GRADIENT FILL
pMid1 = plot(osc_scaled * 0.8 + 50 * 0.2, color=na, display=display.none)
pMid2 = plot(osc_scaled * 0.6 + 50 * 0.4, color=na, display=display.none)
pMid3 = plot(osc_scaled * 0.4 + 50 * 0.6, color=na, display=display.none)
pMid4 = plot(osc_scaled * 0.2 + 50 * 0.8, color=na, display=display.none)
fill(pOsc, pMid1, color=fillEnabled ? color.new(lineColor, fillTransparency) : na)
fill(pMid1, pMid2, color=fillEnabled ? color.new(lineColor, fillTransparency + 5) : na)
fill(pMid2, pMid3, color=fillEnabled ? color.new(lineColor, fillTransparency + 10) : na)
fill(pMid3, pMid4, color=fillEnabled ? color.new(lineColor, fillTransparency + 15) : na)
// SIGNALS
longSignalObos = ta.crossover(osc_scaled, osLevel)
shortSignalObos = ta.crossunder(osc_scaled, obLevel)
// plotshape
plotshape(longSignalObos ? osc_scaled : na, location=location.bottom, color=osColor, style=shape.triangleup, size=size.tiny, title='Buy (OS)')
plotshape(shortSignalObos ? osc_scaled : na, location=location.top, color=obColor, style=shape.triangledown, size=size.tiny, title='Sell (OB)')
// ALERTS
alertcondition(longSignalObos, 'Buy (Oversold)', 'Oscillator crossed above oversold.')
alertcondition(shortSignalObos, 'Sell (Overbought)', 'Oscillator crossed below overbought.')
답변 1
예스스탁 예스스탁 답변
2025-12-22 13:23:56