Error Could not find function or function reference indicator

El espacio del Foro donde compartir indicadores y estrategias creados con el lenguaje de la plataforma TradingView.
Responder
XavierOrp
Mensajes: 1
Registrado: 16 Ago 2022 18:57

Error Could not find function or function reference indicator

Mensaje por XavierOrp »

Buenas tardes,

Soy Xavier, y me acabo de registrar en este foro sobre la programación "Pine Script".
Soy nuevo en este lenguaje de programación "Pine Script".

He visto el siguiente video de una estrategia para TradingView:

que utiliza los siguientes indicadores:

1- Support and Resistance Levels with Breaks
2- Smoothed Ha Candles
3- Relative Volume RVOL [DepthHouse]

Anteriormente vi algunos videos de Andrés Aristizábal (https://www.youtube.com/c/ANDR%C3%89SARISTIZ%C3%81BAL), sobre cómo crear un indicador en TradingView que es como la fusión de varios indicadores:



He cogido el código Pine Script de los 3 indicadores anteriores, y tras algunos pequeños cambios (he desactivado las funciones study, he añadido al principio la función indicator, he desactivado las 4 alertcondition, y he añadido las 2 alertcondition que tienen las condiciones de los 3 indicadores al mismo tiempo).

Pero cuando grabo este Script con un nuevo nombre (indicator("SR-SmHA-Vol", shorttitle = " SRSmHAVol ", overlay = true)), siempre me sale el error: "Could not find function or function reference indicator".

Como no controlo esta programación no sé cómo resolver este problema.

El primer y tercer indicadores tienen la versión 4. El segundo indicador tienen la versión 2. No sé si esto es un problema a la hora de unificar las programaciones.

Agradecería alguna ayuda al respecto.

Muchas gracias.
Xavier

P.D.: copio aquí la programación que yo le he puesto:

Código: Seleccionar todo

//@version=4
indicator("SR-SmHA-Vol", shorttitle = " SRSmHAVol ", overlay = true)
//INDICATOR CREATED BY XAVIER, 15 AUG 2022

// SUPPORT AND RESISTANCE LEVELS WITH BREAKS
//////study(title=" Support and Resistance Levels with Breaks",shorttitle = " Support and Resistance Levels with Breaks", overlay = true ,  max_bars_back=1000)
//
toggleBreaks  = input(true, title = "Show Breaks" )
leftBars  = input(15, title = "Left Bars ")
rightBars  = input(15, title = "Right Bars")
volumeThresh  = input(20, title = "Volume Threshold")
//
highUsePivot = fixnan(pivothigh(leftBars, rightBars)[1])
lowUsePivot = fixnan(pivotlow(leftBars, rightBars)[1])
r1 = plot(highUsePivot, color=change(highUsePivot) ? na : #FF0000,  linewidth=3, offset=-(rightBars+1), title="Resistance")
s1 = plot(lowUsePivot, color=change(lowUsePivot) ? na : #233dee,  linewidth=3, offset=-(rightBars+1), title="Support")

//Volume %
short = ema(volume, 5)
long = ema(volume, 10)
osc = 100 * (short - long) / long


//For breaks with volume
plotshape(toggleBreaks and crossunder(close,lowUsePivot) and not (open - close < high - open) and osc > volumeThresh, title = "Break", text = 'B', style = shape.labeldown, location = location.abovebar, color= color.red,textcolor = color.white, transp = 0, size = size.tiny)
plotshape(toggleBreaks and crossover(close,highUsePivot ) and not(open - low > close - open) and osc > volumeThresh, title = "Break", text = 'B', style = shape.labelup, location = location.belowbar, color= color.green,textcolor = color.white, transp = 0, size = size.tiny)

//For bull / bear wicks
plotshape(toggleBreaks and crossover(close,highUsePivot ) and open - low > close - open , title = "Break", text = 'Bull Wick', style = shape.labelup, location = location.belowbar, color= color.green,textcolor = color.white, transp = 0, size = size.tiny)
plotshape(toggleBreaks and crossunder(close,lowUsePivot) and open - close < high - open , title = "Break", text = 'Bear Wick', style = shape.labeldown, location = location.abovebar, color= color.red,textcolor = color.white, transp = 0, size = size.tiny)


////alertcondition(crossunder(close,lowUsePivot) and osc > volumeThresh , title = "Support Broken" , message = "Support Broken")
////alertcondition(crossover(close,highUsePivot) and osc > volumeThresh, title = "Resistance Broken" , message = "Resistance Broken")



//SMOOTHED HEIKEN ASHI CANDLES
//////study(title = "Smoothed Heiken Ashi Candles", shorttitle="Smoothed Ha Candles", overlay=true)
len=input(10)
o=ema(open,len)
c=ema(close,len)
h=ema(high,len)
l=ema(low,len)

haclose = (o+h+l+c)/4
haopen = na(haopen[1]) ? (o + c)/2 : (haopen[1] + haclose[1]) / 2
hahigh = max (h, max(haopen,haclose))
halow = min (l, min(haopen,haclose))

len2=input(10)
o2=ema(haopen, len2)
c2=ema(haclose, len2)
h2=ema(hahigh, len2)
l2=ema(halow, len2)

col=o2>c2 ? red : lime
plotcandle(o2, h2, l2, c2, title="heikin smoothed", color=col)



// RELATIVE VOLUME RVOL
//////study("Relative Volume RVOL [DepthHouse]", overlay=false)

/// Inputs ///
l = input(26, title="Period")
p = input(1.75, title="Threshold")
s = input(14, title="Smoothing Value")
////b = input(title="Volume Breakout based on:", options=["Smoothing Value", "Threshold"], defval="Smoothing Value")

/// Relative Volume Calcuations ///
vol = volume
svol = sma(vol, l)
rvol = vol/svol
srvol = sma(rvol, s)

/// Vol Breakout Condition ///
v_condition = srvol
v_breakout = crossover(rvol,v_condition)

/// oh92 Favorite Colors ///
red   = #ef9a9a     // #ff848a // #FA8072 // #323433 // #ff848a // #FF510D 
green = #95f33b     // #8cffe5 // #6DC066 // #80aebd // #8cffe5 // #5AA650
light = #b2b5be
dark  = #787b86

/// Horizontal Lines ///
hline(0, title="Zero Line")
hline(p, title="Threshold")

/// Plots & Color Calcuations///
plot(rvol, color=rvol>rvol[1]?green:red, style=plot.style_histogram, linewidth=2, transp=0, title="Relative Vol")
//plot(srvol>rvol ? rvol/2 : srvol, color=close>close[1]?green:red, style=plot.style_histogram, linewidth=2, transp=10, title="+/- Vol")
plot(srvol, color=dark, transp=5, title="Smoothed RVol")

/// Breakout Plotshape ///
plotshape(v_breakout, location=location.top, style=shape.diamond, color=close>close[1]?green:red, size=size.auto, transp=0, offset=0, title="Volume Breakout")

/// Alert Conditions ///
////alertcondition(crossover(rvol,srvol), title="Smoothed Vol Breakout", message="{{ticker}}:Volume Breakout based on Smoothed Vol")
////alertcondition(crossover(rvol,p), title="Threshold Vol Breakout", message="{{ticker}}:Volume Breakout based on Threshold")


/// General Alert Conditions ///
alertcondition(crossunder(close,lowUsePivot) and o2>c2 and l2 - close > 1*(h2-l2) and crossover(rvol,srvol) , title = "Sell Signal" , message = "Sell Signal")
alertcondition(crossover(close,highUsePivot) and o2<c2 and close - h2 > 1*(h2-l2) and crossover(rvol,srvol), title = "Buy Signal" , message = "Buy Signal")
Avatar de Usuario
X-Trader
Administrador
Mensajes: 12781
Registrado: 06 Sep 2004 10:18
Contactar:

Re: Error Could not find function or function reference indicator

Mensaje por X-Trader »

Hola Xavier, bienvenido al Foro. Tras revisar el código el problema lo tienes en la segunda línea ya que la función indicator no existe en Pine Script (debes usar necesariamente study o strategy). Por tanto debes quitar el comentario de la línea de Study pero a partir de ahí te salen muchos errores debido a la mezcla de sintaxis de versiones. Mi consejo es que lo revises poco a poco hasta que no te dé error.

Saludos,
X-Trader
"Los sistemas de trading pueden funcionar en ciertas condiciones de mercado todo el tiempo, en todas las condiciones de mercado en algún momento del tiempo, pero nunca en todas las condiciones de mercado todo el tiempo."
Responder

Volver a “Pine Script”