CONVERSION INDICADOR TRADINGVIEW:”Smooth Price Oscillator “
Forums › ProRealTime foro Español › Soporte ProBuilder › CONVERSION INDICADOR TRADINGVIEW:”Smooth Price Oscillator “
- This topic has 1 reply, 2 voices, and was last updated 1 week ago by Iván.
-
-
11/23/2024 at 1:13 PM #240693
Solicito, si es posible, convertir el indicador adjunto:https://es.tradingview.com/script/khcRd2as-Smooth-Price-Oscillator-BigBeluga/
El oscilador de precios suave aprovecha el filtro SuperSmoother de John Ehlers para producir un oscilador claro y suave para identificar tendencias de mercado y puntos de reversión a la media. Al filtrar los datos de precios durante dos períodos distintos, este indicador elimina eficazmente el ruido, lo que permite a los operadores centrarse en señales significativas sin el desorden de las fluctuaciones del mercado.
A ver si Iván el moderador tiene un hueco libre y lo puede traducir.
Muchas gracias.// © BigBeluga
//@version=5
indicator(“Smooth Price Oscillator [BigBeluga]”)// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
// Input variables for length and threshold
int len_smooth = input.int(20, “Smoothing Length”)
float threshold = input.float(1, “Threshold”, step = 0.1)// Length for calculating standard deviation
int len_std = 50// Create an array to store standard deviation values
float[] std_array = array.new<float>(len_std)
// }// FUNCTIONS ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
// @function SuperSmoother filter based on Ehlers Filter
// @param price (float) The price series to be smoothed
// @param period (int) The smoothing period
// @returns [float] Smoothed price
method smoother_F(float price, int period) =>
float step = 2.0 * math.pi / period
float a1 = math.exp(-math.sqrt(2) * math.pi / period)
float b1 = 2 * a1 * math.cos(math.sqrt(2) * step / period)
float c2 = b1
float c3 = -a1 * a1
float c1 = 1 – c2 – c3
float smoothed = 0.0
smoothed := bar_index >= 4
? c1 * (price + price[1]) / 2 + c2 * smoothed[1] + c3 * smoothed[2]
: price
smoothed
// }// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
// Smoothing lines using the SuperSmoother function
float line_long = close.smoother_F(len_smooth * 2)
float line_short = close.smoother_F(len_smooth)// Oscillator calculation
float oscillator = line_short – line_long// Standard deviation for the oscillator
float stdev_osc = ta.stdev(oscillator, len_std)// Populate standard deviation values into the array
for int i = 0 to len_std – 1
array.set(std_array, i, stdev_osc[i])// Shift array if size exceeds len_std
if array.size(std_array) >= len_std
array.shift(std_array)// Normalize the oscillator using the maximum value from the standard deviation array
float normalized_osc = ta.hma(oscillator / array.max(std_array), 30)// Bands for the oscillator
float basis = ta.ema(normalized_osc, 250)
float deviation = 2 * ta.stdev(normalized_osc, 250)
float upper_band = basis + deviation
float lower_band = basis – deviation
// }// PLOT―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
// Plot the upper and lower bands
plot(upper_band, color = color.gray, editable = false)
plot(lower_band, color = color.gray, editable = false)// Plot horizontal lines and fill regions
p1 = plot(threshold, color = #787b867e, editable = false)
p_1 = plot(-threshold, color = #787b867e, editable = false)
p0 = plot(0, color = color.gray, editable = false)
p4 = plot(4, display = display.none, editable = false)
p_4 = plot(-4, display = display.none, editable = false)plot_osc = plot(normalized_osc, color = chart.fg_color, editable = false)
// Fill bands
fill(p0, p1, threshold, 0, na, color.new(#278ed3, 70), editable = false)
fill(p0, p_1, 0, -threshold, color.new(#278ed3, 70), na, editable = false)
fill(p_1, p_4, -threshold, -4, na, color.new(color.aqua, 70), editable = false)
fill(p1, p4, 4, threshold, color.new(color.orange, 70), na, editable = false)
fill(p0, plot_osc, normalized_osc, 0, normalized_osc > 0 ? color.aqua : na, na, editable = false)
fill(p0, plot_osc, normalized_osc, 0, normalized_osc < 0 ? color.orange : na, na, editable = false)
// }// SIGNALS―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
// Buy/Sell signal conditions
bool signal_up = normalized_osc <-threshold and ta.crossover(normalized_osc, normalized_osc[1])
bool signal_dn = normalized_osc > threshold and ta.crossover(normalized_osc[1], normalized_osc)// Remove old labels and create new labels for threshold values
if barstate.islast
label.delete(
label.new(
bar_index, threshold, “+” + str.tostring(threshold),
color = color(na),
textcolor = chart.fg_color,
style = label.style_label_left
)[1]
)label.delete(
label.new(
bar_index, -threshold, str.tostring(-threshold),
color = color(na),
textcolor = chart.fg_color,
style = label.style_label_left
)[1]
)label.delete(
label.new(
bar_index, 0, “Neutral”,
color = color(na),
textcolor = color.gray,
style = label.style_label_left
)[1]
)label.delete(
label.new(
bar_index, upper_band, “Overbought”,
color = color(na),
textcolor = color.orange,
style = label.style_label_left
)[1]
)label.delete(
label.new(
bar_index, lower_band, “Oversold”,
color = color(na),
textcolor = color.aqua,
style = label.style_label_left
)[1]
)// Plot chart signals for mean reversion
plotshape(signal_dn and normalized_osc < upper_band,
location = location.abovebar,
style = shape.xcross,
size = size.tiny,
text = “↷”,
textcolor = chart.fg_color,
color = color.orange,
title = “Mean Reversion Down”,
force_overlay = true
)plotshape(signal_dn and normalized_osc > upper_band,
location = location.abovebar,
style = shape.xcross,
size = size.tiny,
text = “+\n↷”,
textcolor = chart.fg_color,
color = color.orange,
title = “Strong Mean Reversion Down”,
force_overlay = true
)plotshape(signal_up and normalized_osc < lower_band,
location = location.belowbar,
style = shape.circle,
size = size.tiny,
text = “⤻\n+”,
textcolor = chart.fg_color,
color = color.aqua,
title = “Strong Mean Reversion Up”,
force_overlay = true
)plotshape(signal_up and normalized_osc > lower_band,
location = location.belowbar,
style = shape.circle,
size = size.tiny,
text = “⤻”,
textcolor = chart.fg_color,
color = color.aqua,
title = “Mean Reversion Up”,
force_overlay = true
)// Plot oscillator signals at exact levels
plotshape(
series = signal_up ? normalized_osc[1] : na,
title = “”,
style = shape.circle,
location = location.absolute,
size = size.tiny,
color = color.aqua,
force_overlay = false,
offset = -1
)plotshape(
series = signal_dn ? normalized_osc[1] : na,
title = “”,
style = shape.xcross,
location = location.absolute,
size = size.tiny,
color = color.orange,
force_overlay = false,
offset = -1
)
// }11/26/2024 at 5:05 PM #240787Aquí tienes:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889//-------------------------------------------------////PRC Smooth Price Oscillator//version = 0//26.11.2024//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//-------------------------------------------------//// inputs//-------------------------------------------------//lenSmooth=20threshold=1lenStd=50pi=3.1416//-------------------------------------------------//// Smoothed Line Long Calculation//-------------------------------------------------//periodL=2*LensmoothstepL=2*pi/periodLa1L=exp(-sqrt(2)*pi/periodL)b1L=2*a1L*cos((sqrt(2)*stepL/periodL)*180/pi)c2L=b1Lc3L=-a1L*a1Lc1L=1-c2L-c3Lif barindex<4 thenLineLong=closeelseLineLong=c1L*(close+close[1])/2+c2L*LineLong[1]+c3L*LineLong[2]endif//-------------------------------------------------//// Smoothed Line Short Calculation//-------------------------------------------------//periodS=LensmoothstepS=2*pi/periodSa1S=exp(-sqrt(2)*pi/periodS)b1S=2*a1S*cos((sqrt(2)*stepL/periodS)*180/pi)c2S=b1Sc3S=-a1S*a1Sc1S=1-c2S-c3Sif barindex<4 thenLineShort=closeelseLineShort=c1S*(close+close[1])/2+c2S*LineShort[1]+c3S*LineShort[2]endif//-------------------------------------------------//// Oscillator Calculation//-------------------------------------------------//oscillator = LineShort-LineLong//-------------------------------------------------//// Standard deviation for the Oscillator//-------------------------------------------------//stdevOsc=std[lenStd](oscillator)//-------------------------------------------------//// normalize the Oscillator//-------------------------------------------------//MaxstdevOsc=highest[lenStd](stdevOsc)normalizedOsc=hullaverage[30](oscillator/MaxstdevOsc)if normalizedOsc> 0 thenr=0g=188b=212elser=255g=152b=0endifif barindex>2*lenStd+31 thencolorbetween(normalizedOsc,0,r,g,b,100)endif//-------------------------------------------------//// Bands for the oscillator//-------------------------------------------------//basis=average[250,1](normalizedOsc)deviation=2*std[250](normalizedOsc)upperband=basis+deviationlowerband=basis-deviation//-------------------------------------------------//// Signals//-------------------------------------------------//signalup=normalizedOsc<-threshold and normalizedOsc>normalizedOsc[1] and normalizedOsc[1]<normalizedOsc[2]signaldown=normalizedOsc>threshold and normalizedOsc<normalizedOsc[1] and normalizedOsc[1]>normalizedOsc[2]if signalup thendrawpoint(barindex,normalizedOsc,2)coloured("aqua")elsif signaldown thendrawpoint(barindex,normalizedOsc,2)coloured("orange")endif//-------------------------------------------------//return normalizedOsc as "Normalized Oscillator" coloured("darkblue")style(line,2),upperband as "UpperBand" coloured("grey"),lowerband as "LowerBand" coloured("grey"), threshold as "+Treshold"coloured("GREY"),-threshold as "-Treshold"coloured("GREY")1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on