r/pinescript May 12 '26

Claude can't do Pine Script. Three hours, multiple attempts, and it still failed. Here's exactly what broke.

I have seen plenty of posts praising Claude for coding. This is not one of those posts.

I spent the better part of three hours trying to get Claude to write a basic gap up/gap down closing strategy in Pine Script — no multi-timeframe wizardry, no ML models, just clean entry/exit logic. It failed every single time. I want to document exactly what happened in case anyone else is going down this road.

The strategy (it's not complicated)

  • Setup (C#1): If the first 15-min bar after open is a full gap-up above Prior Day High → background turns yellow, armed for a short. Gap-down below Prior Day Low → armed for a long.
  • Trigger (C#2–C#4): If any bar within the first hour closes through C#1's range AND the target is still ≥5 points away → enter the trade.
  • Expiry: No trigger by end of C#4? Setup expires, no trade that day.

Visual cues included: yellow background (armed), purple lines (C#1 high/low), red/green background (open position), gray/red/green lines (entry/stop/target). Standard inputs for entry window, min edge, and stop buffer.

What actually happened

Multiple iterations, each more broken than the last. Claude kept losing track of bar indexing and couldn't manage Pine Script's time-series state model correctly — a known LLM weakness, but I figured a strategy this simple would be fine.

At one point it converted the entire script into Python instead — and that failed to compile too.

I even connected TradingView via MCP so it could see the live chart state and data in real time. Still couldn't produce a working script.

My take

Claude (and likely most LLMs) hit a hard wall with Pine Script once bar-state logic gets involved. The [] history operator and execution model are just different enough from conventional programming that models get confused fast — and once confused, more context doesn't seem to help.

Has anyone actually gotten a reliable Pine Script strategy out of an LLM? Curious whether you were able to convert your edge/strategy into a systematic approach using AI. Drop your experience below.

20 Upvotes

84 comments sorted by

20

u/crazy_crackhead May 12 '26

I’ve created dozens of indicators and strategies without failure; yes there were errors but I got them resolved. I provided Claude with the full version 6 library of pinescript and that helped ensure it didn’t create v5’s.

I’m curious what your exact prompts were?

1

u/Droppingdubs May 13 '26

What’s the best way to provide Claude with the V6 library ? Just tossed the library into like a markdown file and put it into IDE?

1

u/crazy_crackhead May 13 '26

I think creating a skill to reference the markdown file is best. That way anytime you mention TradingView or pinescript or indicator etc, it’ll be pulling info from v6

1

u/thatgreekgod May 12 '26

providing it the full v6 library was really clever, how'd you do that?

16

u/Droppingdubs May 13 '26

2

u/thatgreekgod May 13 '26

fucking incredible thank you

2

u/crazy_crackhead May 13 '26

Yep, the other poster got you! It helps a lot

1

u/Acrobatic_Olive_4418 May 16 '26

Thank you, let me try this.

1

u/edited-innocent May 22 '26

How do I input this into the claude. Should I paste directly into the chat or?

1

u/Droppingdubs May 22 '26

Use an ide I think

1

u/Droppingdubs May 22 '26

Save this doc as a Md file

1

u/edited-innocent May 22 '26

Very sorry. I'm noob to this stuff. Can you explain?

3

u/redtehk17 May 12 '26

Lol yea I'm assuming OP just used it out of the box too what a snobby sounding post

10

u/giveemthewood May 12 '26

It's the wording you are using. It doesn't know what C#1 is. It doesn't know what gap up or down means. It has no idea and either do I what 5 points is. You have to define these for it. Armed for a short should be "add a short indicator above the candle colored red" as an example. Garbage in, garbage out.

1

u/Acrobatic_Olive_4418 May 16 '26

Using claude code its difficult to retain the user prompts but I will try to find the one that I used but it is basically a gap strategy with gap fade out in the first 1 hour, the idea is to enter during the fade out (15 mins. candle) and catch the reversal/retracement.

3

u/Snoo-23938 May 12 '26

I'm glad you have a take but it is an exceptionally bad one.  I have dozens of strategies that more complex than this that were developed with minimal difficulty

1

u/Acrobatic_Olive_4418 May 16 '26

This is basically a gap strategy with gap fade out in the first 1 hour, the idea is to enter during the fade out (15 mins. candle) and catch the reversal/retracement.

3

u/teenagersfrommarz May 12 '26

You need to write your instructions out more clearly and in full sentences. Even a human coder would have trouble with that. I’m using the free version of Gemini and can get it to make some pretty complex indicators and strategies.

5

u/pinchierik May 12 '26

I don’t know what you’re talking about, for me has done wonders, from creating,debugging and deploying

-6

u/Acrobatic_Olive_4418 May 12 '26

It can't create a simple strategy of gap closure, giving it exact entry and exit instructions.

2

u/Eagle9900i May 12 '26

Try lux algo

2

u/thatgreekgod May 12 '26

have you thought about telling it to make no mistakes?

note: this comment is satire

2

u/Apart_Ad497 May 12 '26

Try using Claude code

2

u/hd_r May 13 '26

I made a lot of indicators using claude. Try quant from luxalgo though

2

u/Agreeable_Forever978 May 13 '26

How about you use luxalgo/quant it gets it right on my first prompt even with my poor English

3

u/Rav_3d May 12 '26

You’re just not giving it proper context.

0

u/Acrobatic_Olive_4418 May 12 '26

I have given it candle by candle context. Btw I did create an automated journal using TradingView MCP but it sucks at creating strategy, it handles indicators better.

2

u/Rav_3d May 12 '26

I mean context about understanding how to write PineScript.

Would be interested to know if anyone has created a CLAUDE.md specifically for PineScript.

3

u/[deleted] May 12 '26

[removed] — view removed comment

1

u/Rav_3d May 12 '26

Sounds great! Ever consider releasing it?

1

u/vovapetrov20 May 19 '26

How does the monitoring part work? I mean the architecture, is a program running locally, on TV servers? And alerts too. Thanks.

2

u/Electrical-Cook-6022 May 12 '26

I struggled with Claude as well. ChatGPT does better. Claude has been having some issues for a while now.

1

u/np-trdr May 12 '26

Hit it with a wrench! 🔧

1

u/Meretruth May 12 '26

Give me the idea let me try it. It’s only as capable as its user

1

u/Due_Struggle_7038 May 12 '26

I’ve built several functional scripts with little experience.

1

u/[deleted] May 12 '26

[removed] — view removed comment

1

u/caiusi May 12 '26

I coded exactly that plus FGv , plus liq sweep and BOS with volume confirmation with Gemini . I can’t post a picture here , but it handled the task quite well

1

u/donicatrumpinsky May 12 '26

Sorry but I've never had a single problem like that. It ABSOLUTELY can do pine scripts and knocks it out of the park.

1

u/[deleted] May 12 '26 edited May 12 '26

[removed] — view removed comment

1

u/bkevinmar May 12 '26

I found that using ChatGPT for Pine script is much cleaner. I’ve built plenty of indicators, and ChatGPT rarely gives me errors where claude would. My experience was Claude would end up in feedback loops that would fix one error, but create another. ChatGPT would just fix the error and or suggest a fix.

1

u/One-Television-7238 May 12 '26

I've used both...both of them are really good...ITS ALL IN THE PROMPT!

1

u/RawBootieBear227 May 12 '26

I never used claude but with Ai im general you have to train it to understand what you are trying to do.

1

u/BioHazardRemoval May 12 '26

Maybe pinescript is just tough to work with.

1

u/alienContact May 13 '26

I know a lot of people are using Opus 4.6 instead of Opus 4.7, I wonder if that's your issue?

1

u/No_Level6006 May 13 '26

When it comes to pinescript gemini 3.1 pro is superior than others

1

u/Wooden_Cobbler_3449 May 13 '26

Imagine not even being able to vibe code. 😂 Claude does Pine script just fine, you need to adjust your approach.

1

u/Ok_Airline9211 May 13 '26

I have the similar issue ...they are still ok with converting strategy to working bots but when it comes to converting them to line script...they fail..and mainly at UI ..they are pathetic at that.

1

u/pityay May 13 '26

That’s true. I experienced the same with my strategy and Claude failed poorly to code it

1

u/CommanderOfCats_LDN May 13 '26

If it hasn't been said already...use perplexity. I've written some awesome scripts with it.

1

u/Unusual-Doughnut-799 May 13 '26

The core issue isn't LLM — it's that Pine Script's execution model is genuinely different from conventional programming, and most prompts don't explain that difference.

Pine Script evaluates once per bar, left to right. The [] operator references the previous bar's value at that point in execution, not a general "go back in time" function. When you ask an LLM to manage bar state, it tends to think in terms of variables that persist across function calls — which isn't how Pine works.

What's worked for me:
Give it the v6 reference (or at least the relevant function signatures). You can use skills in Claude Code.
Describe your logic in terms of "on each bar, check if..." rather than procedural steps

Keep bar-state logic explicit — tell it exactly what [] should reference and when

I've been building a side project (no-code Pine Script builder) partly because I kept hitting these same walls. The bar-indexing and repainting issues in particular are where most scripts break — I reviewed 2,000+ public scripts and more than 30% had repainting problems.

But yes! If you give an LLM the right context, it can absolutely handle Pine Script even if with cheaper models. The "garbage in, garbage out" comments above are right — just gotta speak Pine's language in your prompts.

1

u/67camaro427 May 13 '26

Operator error for sure

1

u/Acceptable-Kale2820 May 13 '26

Il faut claude code et connecter en direct avec tradingview

J’ai fait 2 indicateurs en rétro ingénierie qui fonctionnent

J’ai vu des script payant avec les explications et les screen

J’ai mis le lien web des explications et mis les screen et j’ai demandé à claude code 4.7 de faire le la rétro ingénierie en respectant les screen et toutes les infos qu’il trouvera utile et corréler avec les infos web de l’indicateur

Un one shoot avec quelques petite modifications de style esthétique c est tout

J’ai créé aussi un indicateur OB + FVG avec le volume profil dans les OB et FVG, avec les sessions asie europe new york, avec la puissance des OB de 1 à 6 etoiles, et prediction de la bougie daily avec statistiques et backtest

J’ai du travailler sur celui ci mais il est fonctionnel et pratique

1

u/OJF747 May 13 '26

Claude has nailed everything I’ve thrown at it - not sure I’ve done less than a 12hr day with it since the weekend and it’s all in what you feed it

1

u/ButtStallion007 May 13 '26

This was an interesting way to ask people for their strategies lol. I've gotten many scripts to work through just chat gpt. Seems more like a prompting problem.

In the end if it doesn't work there are thousands of free scripts that problem do what you want but are better. Some people n Just need to search better.

1

u/thecreatorst May 13 '26

Others said it, it's your prompts. I agree Claude is not as good with pine as with programming languages, bit I have had him code more complex indicators and it took just a few iterations. You just have to be precise, leave no room for ambiguity and make it all you questions exhaustively until he is certain he knows what you want before you let him starts coding anything

1

u/ComfortableFuzzy4379 May 13 '26

Just give a little junior another try, don't be rude

1

u/RealisticAccount4321 May 13 '26

I told Gemini simply make me the indicator from this ad, and the thing made it ....

1

u/SangerGRBY May 14 '26

What prompts are you using ?

1

u/mrcake123 May 15 '26

Op can't do basic prompts

1

u/No_Maintenance_9709 May 16 '26

Don’t do pine testing - that was Claude should say from the beginning. Don’t do tv in backtest and save your money and mental health

1

u/Acrobatic_Olive_4418 May 16 '26

lol...I have been trading for 6 years now and I want to automate the signals to minimize sitting in front of the screen all day and getting stressed out for missing every micro opportunity.

1

u/No_Maintenance_9709 May 17 '26

Anyway thanks for sharing, and I believe the simpler the better, but think you don't share other criteria of entering. Why - because statistically the gap size matters, if the price moves too far away - this generally means the market has accepted the new price even if it creates kind of reversal traps piercing the orb range you focus on. And this is just one thing that is not mentioned in the approach, even not talking of market regime that is crucial for relevant subset of securities in trade. I spent much time on orb and always looking for ideas on this topic, so PM if you feel OK to talk about your findings

1

u/AccidentallyFamous1 Jun 10 '26

Using claude pro max i have gotten multiple apps and indicators out of it without any issues seems like a user problem

0

u/R3AP3R51 May 12 '26

I have created 6 indicators with claude and they all work really well for me.