커뮤니티

지표 부탁 드립니다

프로필 이미지
매치다2
2025-12-20 20:50:07
165
글번호 229233
답변완료

// 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

input : lenSwing(5); input : pivotLevel(0.5); input :lookback(5); // ATR SCALING input :atrLen(14); input :multUp(15); input :multDown(15); // THRESHOLD LEVELS input :obLevel(70); input :osLevel(30); input :maOverbought(60); input :maOversold(40); // SIGNAL SETTINGS input :signalLength(14); input :extraSmooth(10); // COLORS input :bullColor(Green); input :bearColor(Red); input :signalColorBull(Green); input :signalColorBear(Red); input :obColor(Red); input :osColor(Green); input :midLineColor(Gray); input :textColor(white); // GRADIENT SETTINGS input :showOverboughtGradient(true); input :showOversoldGradient(true); input :showOscillatorGradient(true); input :showMaGradient(true); input :fillEnabled(true); input :fillTransparency(75); input :bandTransparency(50); var : rangeUpper(0),rangeLower(0),pivotLine(Nan); var : PH(0),PL(0),avgPH(Nan),avgPL(Nan),cnt(0),osc_raw(Nan); Array : phArray[100](0),plArray[100](0); rangeUpper = 60; rangeLower = 5; ph = SwingHigh(1,h, lenSwing,lenSwing,lenSwing*2+1); pl = SwingLow(1, l, lenSwing,lenSwing,lenSwing*2+1); if ph != -1 Then { For cnt = 99 to 1 { phArray[cnt] = phArray[cnt-1]; } phArray[0] = ph; var1 = 0; var2 = 0; For cnt = 0 to lookback-1 { if phArray[cnt] > 0 Then { var1 = var1 + phArray[cnt]; var2 = var2 + 1; } } avgPH = var1/var2; } if pl != -1 Then { For cnt = 99 to 1 { plArray[cnt] = plArray[cnt-1]; } plArray[0] = pl; var3 = 0; var4 = 0; For cnt = 0 to lookback-1 { if plArray[cnt] > 0 Then { var3 = var3 + plArray[cnt]; var4 = var4 + 1; } } avgPL = var3/var4; } if avgPH > 0 and avgPL > 0 Then { pivotLine = avgPL + (avgPH - avgPL) * pivotLevel; osc_raw = close - pivotLine; } var : alpha(0),ATR(0); var : atr_safe(0),upper_bound(0),lower_bound(0),osc_scaled(0); var : oscSignal(0),ob_gradient_color(0),os_gradient_color(0); alpha = 1 / atrLen ; ATR = IFf(IsNan(ATR[1]) == true, ma(TrueRange,atrLen) , alpha * TrueRange + (1 - alpha) * IFf(isnan(ATR[1])==true,0,ATR[1])); atr_safe = iff(atr > 0 ,atr , 1); upper_bound = atr_safe * multUp; lower_bound = atr_safe * multDown; osc_scaled = 50.0; if osc_raw > 0 Then osc_scaled = 50.0 + 50.0 * (osc_raw / upper_bound); else if osc_raw < 0 Then osc_scaled = 50.0 + 50.0 * (osc_raw / lower_bound); else osc_scaled = 50.0; osc_scaled = max(1.0, min(100.0, osc_scaled)); oscSignal = ma(osc_scaled, signalLength); ob_gradient_color = iff(oscSignal>=maOverbought,obColor,gray); os_gradient_color = iff(oscSignal<=maOversold,osColor,gray); if showOverboughtGradient == true Then plot1(obLevel, "OB Gradient", ob_gradient_color); Else NoPlot(1); if showOversoldGradient == true Then plot2(osLevel, "OS Gradient",os_gradient_color); Else NoPlot(2); Plot3(obLevel, "Overbought", obColor); plot4(osLevel, "Oversold", osColor); plot5(50, "Midline 50", midLineColor); plot6(1, "Min", gray); plot7(100, "Max", gray); var : lineColor(0); lineColor = iff(osc_raw > 0 , bullColor , bearColor); plot8(osc_scaled, "Oscillator 1 100",lineColor); if showOscillatorGradient == true then plot9(osc_scaled, "Osc Gradient",lineColor); Else NoPlot(9); var : smoothSignal(0),dynSignalColor(0); // SMA SMOOTHED + DYNAMIC COLOR + GRADIENT smoothSignal = ma(oscSignal, extraSmooth); dynSignalColor = IFf(smoothSignal > smoothSignal[1],signalColorBull,IFf(smoothSignal < smoothSignal[1],signalColorBear,gray)); // SMA PLOT if showMaGradient == true Then { plot10(smoothSignal, "Signal SMA", dynSignalColor); plot11(smoothSignal, "11", dynSignalColor, 5); plot12(smoothSignal, "12", dynSignalColor, 3); plot13(smoothSignal, "13", dynSignalColor, 1); } Else { Plot10(smoothSignal,"Signal SMA", dynSignalColor); NoPlot(11); NoPlot(12); NoPlot(13); } var : longSignalObos(False),shortSignalObos(False),tx(0); // SIGNALS longSignalObos = CrossUp(osc_scaled, osLevel); shortSignalObos = CrossDown(osc_scaled, obLevel); if longSignalObos == true Then { tx = Text_New_Self(sDate,stime,0,"▲"); Text_SetStyle(tx,2,0); Text_SetColor(tx,osColor); } if shortSignalObos == true Then { tx = Text_New_Self(sDate,stime,100,"▼"); Text_SetStyle(tx,2,1); Text_SetColor(tx,obColor); }