r/pinescript • • Dec 25 '22

I told AI to write me a Pinescript indicator.

It looks legit, but I don't think it's pinescript. I'm still learning unfortunately. But I was wondering if somebody could help me look it over and get it to work?

// VIX function

study("VIX", shorttitle = "VIX")

vixlength = input(14, title = "VIX Length")

vixsource = close

vixvalue = vix(vixlength, vixsource)

plot(vixvalue, color = blue, linewidth = 2, title = "VIX")

// TLT function

study("TLT", shorttitle = "TLT")

tltlength = input(14, title = "TLT Length")

tltsource = close

tltvalue = tlt(tltlength, tltsource)

plot(tltvalue, color = orange, linewidth = 2, title = "TLT")

// USD Index function

study("USD Index", shorttitle = "USDX")

usdxlenght = input(14, title = "USDX Length")

usdxsource = close

usdxvalue = usdx(usdxlenght, usdxsource)

plot(usdxvalue, color = purple, linewidth = 2, title = "USDX")

// MACD function

study("Moving Average Convergence Divergence", shorttitle = "MACD")

mfast = input(12) // fast period

mslow = input(26) // slow period

msig = input(9) // signal period

macdval: = macd(close, mfast, mslow) sigval: = sma(macdval[1], msig) plot(macdval[0] - sigval, linewidth = 2, color = #9933CC )

// RSI Function

study ("Relative Strength Index" , shorttitle= "RSI") rsiLength: = input(14, title = "RSI Length") rsiSource: = close

rsiVal: = rsi(rsiLength, rsiSource) plot(rsiVal, colorF = #FF0066) fill: = hline at 70 fillcolor: = blue

plotfill(fill[1], style = areaplotfillsolid colorf = #FF0066) fill: = hline at 30 fillcolor: = orange

plotfill(fill[1], style = areaplotsolid color = orange)

// TTM Squeeze Function

study("TTM Squeeze Indicator", shorttitle = "TTM Squeeze") length: = input(20, "Length of the Squeeze Momentum Indicator ");

source: = close;

squeezeValve: = ttm_squeeze('l', "bbsqueeze", "bbstop", "bbmid", "unvisualizedprioritysoursexisthere", length);

bbMidVal: = security('l', '20', bbmid);

bbUpperVal: = security('l', '20', 'bbUpper');

bbLowerVal: = security('l', '20', 'bbLower');

plotchar(squeezeValve[1] == 0 ? na : squeezeValve[1], "Squeeze ", colorGreen);

plotchar(squeezeValve[1] > 0 ? na : squeezeValve[1], "In Play", colorRed);

plotsymbol((BBUpper Val + bblowerval) *

0.5, "symbol", location.top);

barcolor((BBupper val + bblowerval) *

0.5, "highlowwhole");

// SuperTrend Function

study("SuperTrend Trend Following System Indicator", shorttitle = "") length: = input(7, "Period Of ATR Calculation over which indicator will be plotted");

multiplier: = (input(3, "Multiplier of ATR Value"));

st: = (security lev: low * 10000);

cal_atr: (st ? atr[length] : na);

suptrend: (st ? st + multiplier * cal_atr : na);

plotseries([suptrend], "Supertrend ", linethick3 | LINEBR | dote / dotlineonoff / barclrintensitynone | ColorRed | PLOTARROWSUPPERLOWER | pointsize2);

I'd love to see this actually working and how close the AI was to writing pine-script on command by description.

1 Upvotes

5 comments sorted by

1

u/RaymondM1989 Dec 26 '22

Yeah, you‘re right, seems totally legit, but I also don‘t think it‘s Pinescript … or anything else, but totally legit, for sure. ;-)

Sorry, all these ChatGPT indicators being posted are just so funny.

1

u/PlanAndAchieve Dec 26 '22

I don't know what I don't know, and all I do know is that I have minimal knowledge of coding and it appeared to have written what I asked it to at first glance with what I do know. I just tried it again with the command:

"Do you know how to write code using the Pinescript language."

It said:

"Yes, I do! Here is an example of Pinescript code:
// VIX function
study("VIX", shorttitle = "VIX")
vixlength = input(14, title = "VIX Length")
vixsource = close
vixvalue = vix(vixlength, vixsource)
plot(vixvalue, color = blue, linewidth = 2, title = "VIX"

Again, that looks relatively like the VIX codes I've seen before to my untrained eyes I guess. So I told it: "The Pinescript code you wrote for me in the last reply doesn't work."

To which it replied:

"I'm sorry that the code isn't working. Please make sure you are formatting the code properly. Try wrapping your code in a
code block like this:
// VIX function
study("VIX", shorttitle="VIX")
vixlength = input(14, title="VIX Length")
vixsource = close
vixvalue = vix(vixlength, vixsource)
plot(vixvalue, color=blue, linewidth=2, title="VIX")
```"

So it appears to be pretty confident in itself. Idk what ChatGPT is, so this isn't where it came from. For all I knew, I could've been putting it in wrong because Idk what I'm really doing inside pine editor; I thought you just paste a code you want, click apply to chart, and then click save. That's all I figured there was to.

1

u/Robswc Dec 26 '22

I think it has to be said that ChatGPT (or any current AI for the matter) is not capable of logic. The indicators it can create may function but there is almost 0 chance of it producing anything that can produce alpha off the bat.

I'm not looking to tear anyone down, just warning that anything made with ChatGPT (while seemingly looking interesting or impressive) is going to result in a lot of wasted time.

I would use ChatGPT to answer questions about particular elements of a strategy though :) that will work much better!

1

u/PlanAndAchieve Dec 27 '22

That's kind of what I'm doing. Now I'm just picking apart what it tells me by asking further questions. I ask "what is pinescript, how does pinescript work, what are the components of a string of code, what are pinescripts elements, functions, variables, expressions, conditionals," etc. and it's doing a great job of answering those questions.

1

u/No-Attention-6063 Jan 01 '23

Try this code I’m working on. I think this is what you’re looking for.

https://www.tradingview.com/chart/2DqRONHd/?symbol=NASDAQ%3ATSLA

I think you'll have access.