✋ A framework for trading strategies with PineTS #103
tripolskypetr
started this conversation in
Ideas
Replies: 1 comment 4 replies
-
|
Very interesting stuff, I'll take a closer look to it later this week. I like the CLI approach it makes it easier for integration with existing AI bots. did you use any of this in a live market data ? if so how did it go ? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
✋ How AI Got Hands for Stock Trading with PineTS
I recently discussed creating a full-fledged trading strategy system based on PineTS, with the ability to seamlessly switch between backtesting, demo account recording, and live trading, as well as integration with Claude Code. And there you have it.
The TradingView Problem: The Human Becomes the Bottleneck
If we discard the marketing, the real process of creating an automated production trading strategy looks like this. TradingView replaced MetaTrader, trading strategies are written on it.
The iteration cost is too high due to clumsy human hands: the number of CSV files either turns the downloads folder into a mess, or running a week's worth of backtest time takes a day of thoughtful work because you need to name and organize files into folders. A human physically can't work that long.
And you can also send the wrong file to the chat and catch look-ahead bias.
The Architectural Flaw of Pine Script
The Pine Script language is syntactic sugar for a for loop where variables are declared both inside and outside the loop block.
As a consequence, if you need to wait for favorable conditions on both fast (15m) and long (4h) timeframes, you get workarounds:
The closest analogy to this code from mathematics is a complex number. The number itself means nothing: you need the dynamics of change in a series of numbers (whether it's generally growing or falling). And double for loops are inefficient (quadratic complexity), so they weren't implemented. And it's also unclear what
barmerge.lookahead_offdoes.Things are even more fun with breakeven math: this code is unreadable, any language model hallucination will indistinguishably create a loss. Meanwhile, the programmer will be convinced that the problem is in the indicators.
And Now It Has Hands
To eliminate the human factor, you need to create a system that will:
Run Pine Script locally self-hosted
Already done at https://github.com/QuantForgeOrg/PineTS. Indicator visualization is already open source, trading strategies are not interesting within the scope of the article.
Ensure time synchronization outside of LLM-editable code
Covered in the article Look ahead Bias. It's important to move critical code out of the AI agent's working zone to avoid sloppy work or hallucinations.
Same code in backtest/live/paper
Covered in the article Second order chaos. It talks about trading strategies in natural language, but seamless live/paper/dev migration is already done.
Maintain structured JSONL logs as markup native to LLM agents
JSONL (JSON Lines) is a format for both datasets in huggingface and for logs. Claude reads them with an extended limit or writes a script itself for quick line search.
Agent Skills file to avoid repeated research on a new chat context
Created automatically when running the command
npx -y @backtest-kit/sidekick. This also allows you to ask regular Claude chat to use backtest-kit code for research by creating a docker container on the server side without touching the programmer's machine.Additionally, since everything is open source, this can be run on any exchange, including those not available in TradingView or where the company has disabled the broker.
Here is PineTS appear: Fixing Pine Script
To combine data from different timeframes, you need to run two separate indicators simultaneously. The complete program code at the link already contains a caching mechanism for the higher 4h timeframe, calculations are optimized.
How Claude Code Uses This
Not only technical, but also multi-timeframe and fundamental analysis is available. Anthropic has already created and maintains internet search tools for Claude, so it will find news on the internet itself and, if necessary, will only open short positions. Also, the
@backtest-kit/ollamapackage and the async nature of thegetSignalfunction allow searching for news and forecasts on the internet on the fly without changing the bot code. But the combination of Claude Code on the web plus GitHub Actions is significantly more convenient: you can give a command to adapt the strategy from an iPad while on vacation.Example of Creating a Trading Bot
Human: Create a crypto trading bot using RSI divergence and volume confirmation
Claude Code:
Claude Code: I see a template with EMA crossover. Modifying it for RSI divergence...
Claude Code: Running backtest on October 2025 (crypto crash period)...
Backtest Results:
Claude Code: Hmm, losses during volatility. I'll add dynamic stops based on ATR and a trend filter...
Claude Code: Rerunning backtest with dynamic stops + trend filter...
Claude Code: Strategy is now profitable. Deploying to paper trading for live validation...
Thank you for Your Attention!
Beta Was this translation helpful? Give feedback.
All reactions