A TradingView indicator built for AI agents.
Indicators were built for human eyes: colors, arrows, lines. An AI agent can't trade on colors. AI Agent Lens breaks down every closed candle into clean, structured JSON and sends it to any AI agent the moment the candle closes. Your agent reads the chart candle by candle, understands the context, and turns it into clear trading signals. You make the final call.
It works with any agent. It's built to shine with long-horizon reasoning models like Claude Fable 5.2.
Open source · MIT license · Pine Script v6 · No repainting
One JSON packet per closed candle with everything a trader looks at:
- Candle breakdown: body, wicks, range versus ATR, where it closed in its range, gap, pattern (engulfing, hammer, doji, inside bar and more)
- The last 5 candles in the same format, so the agent reads the sequence, not one bar
- Regime:
TREND_UP,TREND_DOWN,RANGEorHIGH_VOLATILITY - Trend: EMA 20/50/200 stack, 200 EMA slope, higher-timeframe bias
- Momentum and strength: RSI, MACD histogram, ADX, DI+ and DI-
- Volume and volatility: relative volume, ATR, ATR percentile
- Structure: swing highs and lows, breakouts and breakdowns
- Levels: previous day high and low, VWAP
- Long and short scores (0 to 100) with the five factors behind each score
- Risk map: entry, ATR stop, 1.5R and 3R targets, and live trade status
Full field list: docs/PACKET_SCHEMA.md · Example: examples/sample_packet.json
TradingView chart Your AI agent You
┌───────────────────┐ webhook ┌──────────────────────────┐ ┌──────────────┐
│ AI Agent Lens │ ─────────► │ reads the JSON packet │ ─► │ signal: │
│ closes a candle, │ JSON per │ breaks down the candles │ │ LONG / SHORT │
│ builds a packet │ candle │ applies your rules │ │ WAIT / SKIP │
└───────────────────┘ └──────────────────────────┘ │ entry, stop, │
│ targets, why │
└──────────────┘
- The indicator runs on your TradingView chart and calculates everything on each closed candle.
- One TradingView alert sends the packet to your agent's webhook URL.
- Your agent (Claude Code with Fable 5.2, an n8n flow, your own bot) reads it with the prompt in agent/AGENT_PROMPT.md and returns a signal: decision, confidence, entry, stop, targets, position size, invalidation and why it could fail.
- Open ai-agent-lens.pine and copy all of it.
- In TradingView, open the Pine Editor at the bottom of the chart.
- Delete the default code, paste, and click Save, then Add to chart.
You'll see the EMA ribbon, key levels, swing points and structure breaks, ▲ LONG / ▼ SHORT score labels, position boxes for every setup, and the Agent Readout panel on the right.
- Open the alert dialog (clock icon, or
Alt + A). - Condition:
AI Agent Lens→Any alert() function call. - Notifications: tick Webhook URL and paste your agent's URL (Step 3).
- Leave the message box as it is. The indicator writes the message itself.
- Click Create.
One alert covers one chart (one symbol on one timeframe). Repeat it for every chart you want your agent to watch.
Webhook alerts need a paid TradingView plan with two-factor authentication turned on. On the Essential and Plus plans, alerts expire after 2 months, so recreate them when they do.
Pick one.
git clone https://github.com/roan-maverick/tradingview-indicator-for-ai-agents
cd tradingview-indicator-for-ai-agents
# 1. Start the receiver (Python 3, no installs)
python3 examples/webhook_receiver.py --port 8080 --token YOUR_SECRET
# 2. In a second terminal, give it a public HTTPS address
cloudflared tunnel --url http://localhost:8080Your webhook URL for Step 2 is:
https://<your-tunnel-address>/webhook?token=YOUR_SECRET
Every packet is saved to packets/latest.json, packets/latest/<SYMBOL>_<TF>.json and packets/history.jsonl.
Now open Claude Code in the same folder:
claudeand ask:
Use agent/AGENT_PROMPT.md as your instructions. Read packets/latest.json
and give me the signal for this candle.
More things to ask:
Read every file in packets/latest/ and rank the charts by setup quality.
Combine the HYPE 1h and 4h packets: the 4h sets direction, the 1h sets timing.
Read the last 50 lines of packets/history.jsonl for BTC and tell me how
the momentum and structure changed over the session.
- Create a Webhook trigger and copy its URL into the TradingView alert.
- Add an AI step (Claude or any LLM). Use the block in agent/AGENT_PROMPT.md as the system prompt and the webhook body as the user message.
- Send the reply to Telegram, Discord, Slack or email.
Point the webhook at your server. The body is plain JSON with the schema ai-agent-lens/v1. Check the schema field, then use the fields directly or pass the packet to your model with the agent prompt.
Example output from the agent prompt (examples/sample_signal.json):
{
"decision": "LONG",
"confidence": 74,
"entry": 70.71,
"stop": 69.882,
"target_1": 71.952,
"target_2": 73.194,
"candle_read": "Three candles of steady higher closes, a bearish engulfing shakeout that held above the last swing low, then a bullish engulfing on 1.31x volume that closed in the top quarter of its range and above the last swing high.",
"invalidation": "A 1h close back below 70.48 or a touch of the 69.882 stop",
"why_this_could_fail": "This could be a relief rally inside a larger daily pullback."
}The example files are illustrative, not live market data or a real trade.
| Element | What it shows |
|---|---|
| Agent Readout panel | A clean signal card: LONG, SHORT or WAIT, regime, scores, confluence, the open trade with live R multiple, and market context |
| Position boxes | Every setup is drawn like TradingView's long/short tool: a red risk box (entry to stop) and a green reward box (entry to target 2) with a dashed target 1 line. Boxes extend while the trade is open and stop where it closed |
| Price tags | ENTRY, STOP, T1 and T2 tags on the right of the open trade |
| Setup labels | ▲ LONG 81 / ▼ SHORT 77. Hover a label to see the factor breakdown behind the score |
| EMA ribbon | EMA 20 and 50 with a green or red fill between them, and a glowing EMA 200 |
| Structure | Confirmed swing highs and lows as dots, and BOS markers when price breaks them |
| Key levels | Previous day high and low (PDH, PDL) and VWAP |
| Optional | Candles colored by score, background shaded by regime |
A clean signal card in the corner of the chart:
| Row | Shows |
|---|---|
| Header | AI AGENT LENS, symbol and timeframe |
| Signal | LONG, SHORT or WAIT in large type, with the score |
| Status | Setup active, target 1 hit, long building (64 of 70), or no confluence yet |
| Regime | Trend up, trend down, range, high volatility |
| Long / Short | Both scores |
| Confluence | How many of the five factors are clearly aligned |
| Entry, Stop, Targets, Open P&L | The open trade and its live R multiple (shown only while a trade is open) |
| Context | Higher-timeframe bias, RSI, ADX |
| Candle, Structure | Current candle pattern and market structure |
Switch Panel mode to Compact to keep only the signal, regime, scores and confluence. The indicator keeps the chart's status line clean (no input values printed next to its name), and every value is also in TradingView's Data Window.
Each score is out of 100: five factors, 20 points each.
| Factor | Long side gets points when |
|---|---|
| Trend | EMA 20 > 50 > 200 and close above EMA 20 |
| Momentum | RSI above 50 (not overbought), MACD histogram positive and rising |
| Strength | DI+ above DI- and ADX at or above 20 |
| Volume | Bullish candle on above-average volume |
| Higher timeframe | 4h close above its 50 EMA |
The short score mirrors it. A setup fires when a score crosses 70 on a closed candle and the regime does not point the other way. While a trade is open, repeat signals in the same direction are ignored, so one move gives one signal. Full rules: docs/SPECIFICATION.md.
| Setting | Default | What it changes |
|---|---|---|
| Setup score threshold | 70 | Higher = fewer, stronger setups |
| Higher timeframe | 240 (4h) | Use D on a 4h chart, W on a daily chart |
| Block setups in HIGH_VOLATILITY | On | Skips setups during volatility spikes |
| Stop distance | 1.5 x ATR | Wider or tighter stops |
| Target 1 / Target 2 | 1.5R / 3R | Reward multiples |
| Send JSON packet | Every bar close | Or only setups and trade updates, or off |
| Recent candles in packet | 5 | 1 to 10 |
| Show packet preview on chart | Off | Prints the live packet next to price, useful for checking your setup |
| Panel mode | Full | Full or Compact |
| Panel position, text size | Top right, Small | Where and how big the panel is |
| Show position boxes | On | Risk and reward boxes for every setup |
| Color candles by score | Off | Green or red candles when a side leads |
Does it repaint? No. Setups, trade tracking and packets use closed candles only. Higher-timeframe and daily values use only bars that have already closed. Swing points appear 5 bars after the pivot and never move.
Which markets and timeframes?
Any symbol on TradingView. Crypto, stocks, forex, futures. Intraday timeframes (5m to 4h) get the most out of VWAP and previous-day levels. Symbols without volume data get null volume fields.
Can I use it on the free TradingView plan? Yes. The indicator, panel and Data Window all work. Sending packets to an agent needs webhook alerts, which need a paid plan.
How many packets will I get? One per closed candle per chart. A 1h chart sends 24 a day. Switch "Send JSON packet" to "Setups and trade updates" to receive only the important ones.
Does it place trades? No. It produces data and signals. Your agent can be connected to a broker if you choose, but this repository never places orders.
tradingview-indicator-for-ai-agents/
├── ai-agent-lens.pine the indicator (Pine Script v6)
├── agent/AGENT_PROMPT.md system prompt for your AI agent
├── docs/SPECIFICATION.md every calculation and rule
├── docs/PACKET_SCHEMA.md every field in the JSON packet
├── examples/webhook_receiver.py receive packets locally (Python 3, no installs)
├── examples/sample_packet.json example packet
├── examples/sample_signal.json example agent signal
└── LICENSE MIT
This project is for education and research. It is not financial advice. The indicator describes the chart using fixed rules; it does not predict the future. Signals from any AI agent can be wrong. Test on paper first, size small, and never risk money you can't afford to lose.
MIT. Use it, fork it, build on it.