Cómo crear un Indicador en TradingView
TradingView ya es una de las plataformas que más usan los traders a la hora de analizar gráficos y proyectas sus análisis técnicos. Y no sólo se queda en los análisis, sino que también puedes conectar tu broker para poder enviar órdenes desde allí, o también crear tu propio sistema automatizado.
En este artículo nos centramos en la creación de un indicador utilizando el lenguaje nativo de programación de TradingView: Pine Script. No te pierdas el siguiente vídeo en el que explico cómo hacerlo:
Tabla de Contenido
Script simple
En el vídeo programamos un script sencillo que tiene en cuenta 2 EMAs y, con esos datos, calculamos la diferencia entre ellas cuando se separan y, también, el momento cuando se cruzan.
study("Mi script", overlay=false)
int periodo_1 = input(title="EMA rápida", type=input.integer, defval=10)
int periodo_2= input(title="EMA lenta", type=input.integer, defval=50)
e10 = ema(close,10)
e50 = ema(close,50)
dif = abs(e10-e50)
bgcolor(color=cross(e10, e50) ? color.fuchsia : na,transp=70)
plot(series=dif,linewidth=1, style=plot.style_histogram)
plot(e10,linewidth=2,color=color.green)
plot(e50,linewidth=2, color=color.red)
Script Pivot Points
Aquí tienes el script del indicador Pivot Points que enseño en el vídeo para que lo puedas incorporar a tu lista de indicadores e incluso modificarlo a tu gusto.
study("Mi script", overlay=true)
higherTF = input("M", type=input.resolution)
prevCloseHTF = security(syminfo.tickerid, higherTF, close[1], lookahead=true)
prevOpenHTF = security(syminfo.tickerid, higherTF, open[1], lookahead=true)
prevHighHTF = security(syminfo.tickerid, higherTF, high[1], lookahead=true)
prevLowHTF = security(syminfo.tickerid, higherTF, low[1], lookahead=true)
pLevel = (prevHighHTF + prevLowHTF + prevCloseHTF) / 3
r1Level = pLevel * 2 - prevLowHTF
s1Level = pLevel * 2 - prevHighHTF
var line r1Line = na
var line pLine = na
var line s1Line = na
if pLevel[1] != pLevel
line.set_x2(r1Line, bar_index)
line.set_x2(pLine, bar_index)
line.set_x2(s1Line, bar_index)
line.set_extend(r1Line, extend.none)
line.set_extend(pLine, extend.none)
line.set_extend(s1Line, extend.none)
r1Line := line.new(bar_index, r1Level, bar_index, r1Level, extend=extend.right)
pLine := line.new(bar_index, pLevel, bar_index, pLevel, width=3, extend=extend.right)
s1Line := line.new(bar_index, s1Level, bar_index, s1Level, extend=extend.right)
label.new(bar_index, r1Level, "R1", style=label.style_none)
label.new(bar_index, pLevel, "P", style=label.style_none)
label.new(bar_index, s1Level, "S1", style=label.style_none)
if not na(pLine) and line.get_x2(pLine) != bar_index
line.set_x2(r1Line, bar_index)
line.set_x2(pLine, bar_index)
line.set_x2(s1Line, bar_index)
Script Línea de Regresión
Por último te dejo el indicador para que te calcule una línea de regresión de cierres, máximos y mínimos:
study("Linear Regression", shorttitle="LinReg", overlay=true)
upperMult = input(title="Upper Deviation", defval=2)
lowerMult = input(title="Lower Deviation", defval=-2)
useUpperDev = input(title="Use Upper Deviation", defval=true)
useLowerDev = input(title="Use Lower Deviation", defval=true)
showPearson = input(title="Show Pearson's R", defval=true)
extendLines = input(title="Extend Lines", defval=false)
len = input(title="Count", defval=100)
src = input(title="Source", defval=close)
extend = extendLines ? extend.right : extend.none
calcSlope(src, len) =>
if not barstate.islast or len <= 1
[float(na), float(na), float(na)]
else
sumX = 0.0
sumY = 0.0
sumXSqr = 0.0
sumXY = 0.0
for i = 0 to len - 1
val = src[i]
per = i + 1.0
sumX := sumX + per
sumY := sumY + val
sumXSqr := sumXSqr + per * per
sumXY := sumXY + val * per
slope = (len * sumXY - sumX * sumY) / (len * sumXSqr - sumX * sumX)
average = sumY / len
intercept = average - slope * sumX / len + slope
[slope, average, intercept]
[s, a, i] = calcSlope(src, len)
startPrice = i + s * (len - 1)
endPrice = i
var line baseLine = na
if na(baseLine) and not na(startPrice)
baseLine := line.new(bar_index - len + 1, startPrice, bar_index, endPrice, width=1, extend=extend, color=color.red)
else
line.set_xy1(baseLine, bar_index - len + 1, startPrice)
line.set_xy2(baseLine, bar_index, endPrice)
na
calcDev(src, len, slope, average, intercept) =>
upDev = 0.0
dnDev = 0.0
stdDevAcc = 0.0
dsxx = 0.0
dsyy = 0.0
dsxy = 0.0
periods = len - 1
daY = intercept + (slope * periods) / 2
val = intercept
for i = 0 to periods
price = high[i] - val
if (price > upDev)
upDev := price
price := val - low[i]
if (price > dnDev)
dnDev := price
price := src[i]
dxt = price - average
dyt = val - daY
price := price - val
stdDevAcc := stdDevAcc + price * price
dsxx := dsxx + dxt * dxt
dsyy := dsyy + dyt * dyt
dsxy := dsxy + dxt * dyt
val := val + slope
stdDev = sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / sqrt(dsxx * dsyy)
[stdDev, pearsonR, upDev, dnDev]
[stdDev, pearsonR, upDev, dnDev] = calcDev(src, len, s, a, i)
upperStartPrice = startPrice + (useUpperDev ? upperMult * stdDev : upDev)
upperEndPrice = endPrice + (useUpperDev ? upperMult * stdDev : upDev)
var line upper = na
lowerStartPrice = startPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
lowerEndPrice = endPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
var line lower = na
if na(upper) and not na(upperStartPrice)
upper := line.new(bar_index - len + 1, upperStartPrice, bar_index, upperEndPrice, width=1, extend=extend, color=#0000ff)
else
line.set_xy1(upper, bar_index - len + 1, upperStartPrice)
line.set_xy2(upper, bar_index, upperEndPrice)
na
if na(lower) and not na(lowerStartPrice)
lower := line.new(bar_index - len + 1, lowerStartPrice, bar_index, lowerEndPrice, width=1, extend=extend, color=#0000ff)
else
line.set_xy1(lower, bar_index - len + 1, lowerStartPrice)
line.set_xy2(lower, bar_index, lowerEndPrice)
na
// Pearson's R
var label r = na
transparent = color.new(color.white, 100)
label.delete(r[1])
if showPearson and not na(pearsonR)
r := label.new(bar_index - len + 1, lowerStartPrice, tostring(pearsonR, "#.################"), color=transparent, textcolor=#0000ff, size=size.normal, style=label.style_labelup)
Espero que te haya gustado esta entrega y, si es así, pronto volveré con nuevos aprendizajes sobre la plataforma TradingView.
y como puedo meterlos los tres dentro del mismo indicador, ya que asi tradingview lo detecta como uno y no como tres, y podre añadir mas.
Your article helped me a lot, is there any more related content? Thanks!
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your article helped me a lot, is there any more related content? Thanks!
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://accounts.binance.info/en/register?ref=JHQQKNKN
Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.com/fr-AF/register?ref=JHQQKNKN
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.info/register?ref=P9L9FQKY
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.com/register?ref=P9L9FQKY
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Your article helped me a lot, is there any more related content? Thanks!
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
thc gummies near me online with express delivery
Yo, check out leavenk88! Heard some buzz about it. Anyone tried it out? Lemme know if it’s worth my time and wallet!
v88club – yeah, I checked it out! Good vibes, feels like a proper club. A good place get a fun experience. Join the club here: v88club
Been playing at phrushcasino for a bit now, and gotta say, I’m enjoying the rush! Games are fun, payouts seem pretty legit. Give it a look if you’re looking for a new thrill! Check it out here: phrushcasino
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Bet365br1, a casa que a gente já conhece e confia. Sempre com as melhores opções de apostas e um site fácil de navegar. Bora fazer um green! Confere lá: bet365br1
1xbetkorea seems super popular here. Checked it out and the odds are pretty competitive. Good for those who understand Korean well or use translation. Link here: 1xbetkorea
Downloaded the win88apps app the other day. Seems legit! The mobile experience is smooth, and I can play anywhere. Convenience is key, right? Give the app a shot: win88apps
Anyone else tried win78vn8? I’ve seen it around. I’m always looking for new places to check out. Any recommendations on games to play? Click here: win78vn8
Looking for some slot action? top646slot seems alright. The interface is decent and the games look pretty interesting. Might be worth a try. You can click here to get in top646slot
RG777, eh? Heard some buddies talking about it. Thinking of hopping on and seeing what the fuss is all about. Good payouts rumored… Fingers crossed! Give RG777 a shot: rg777
Hey, so I signed up for 58jlvip. Its VIP features help me out here. I find it’s quite worth the sign up, so I recommend it.
Yo, 2jili is where it’s at! Seriously, been grinding there for a while and the bonuses are legit. Definitely worth checking out. Give it a shot at 2jili!
Alright alright, 377jilicasino, I see you! Games run smooth and I actually landed a decent win last week. Gotta keep it real, though, still testing the waters but so far, so good. Check it yourself: 377jilicasino.
G6666win, eh? Name’s kinda catchy. Gave it a whirl and the slots are decent. Haven’t hit the jackpot yet, but I’m still trying! Maybe you’ll have better luck at g6666win.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
So I checked out apphp88 the other day. Nothing really blew my mind, same old stuff. But could kill time on the bus? The app is worth checking out. Give it a try before you judge! apphp88
IC79club, never heard of it before! Guess I’ll have to investigate and see if it’s the new hotness in the online casino world. Wish me luck! ic79club
Metbox, Metbox, sounds different I’m intrigued! Is it gaming? Is it crypto? Either way, I’m checking it out. Bring on the surprises metbox
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Roulette’s randomness is fascinating – the math really dictates outcomes! Seeing platforms like boss77 casino prioritize secure KYC & localized payments for Filipino players is smart – builds trust, essential for any game of chance! 🤔
Thanks for sharing. I read many of your blog posts, cool, your blog is very good. https://accounts.binance.info/en/register-person?ref=JHQQKNKN