@kuandotdev/indicator 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -7
- package/package.json +4 -1
- package/project/.cursor/rules/agent-docs.mdc +16 -0
- package/project/.cursor/rules/api-credential-storage.mdc +16 -0
- package/project/.cursor/rules/pinescript-v6.mdc +16 -0
- package/project/.cursor/rules/stock-model-forecast.mdc +16 -0
- package/project/.cursor/rules/system-prompt-injection.mdc +16 -0
- package/project/.cursor/rules/system-prompt-updater.mdc +16 -0
- package/project/.cursor/rules/tradingview-stock-data.mdc +16 -0
- package/project/.env.example +44 -0
- package/project/.npm-packaged-project +1 -0
- package/project/.pi/APPEND_SYSTEM.md +338 -0
- package/project/.pi/settings.json +8 -0
- package/project/AGENTS.md +538 -0
- package/project/CLAUDE.md +538 -0
- package/project/GEMINI.md +538 -0
- package/project/Makefile +488 -0
- package/project/README.md +419 -0
- package/project/conda-env-active.sh +98 -0
- package/project/conda-env-deactive.sh +42 -0
- package/project/docs/agent-install.md +446 -0
- package/project/docs/agent-skill-directory.md +222 -0
- package/project/docs/integration.html +271 -0
- package/project/packages/indicator/README.md +39 -0
- package/project/packages/indicator/package.json +40 -0
- package/project/packages/indicator/scripts/build-project-snapshot.js +57 -0
- package/project/packages/indicator/src/cli.js +368 -0
- package/project/packages/tradingview-stock-data-skill/README.md +112 -0
- package/project/packages/tradingview-stock-data-skill/extensions/stock-prompt-injector.ts +121 -0
- package/project/packages/tradingview-stock-data-skill/package.json +35 -0
- package/project/packages/tradingview-stock-data-skill/scripts/postinstall.sh +73 -0
- package/project/packages/tradingview-stock-data-skill/skills/tradingview-stock-data/SKILL.md +241 -0
- package/project/pyproject.toml +68 -0
- package/project/screenshots/.gitkeep +0 -0
- package/project/scripts/indicators/example_rsi_bands.pine +27 -0
- package/project/scripts/indicators/tsla_levels.pine +57 -0
- package/project/skills/agent-docs/SKILL.md +56 -0
- package/project/skills/api-credential-storage/SKILL.md +83 -0
- package/project/skills/api-credential-storage/scripts/upsert_env.py +151 -0
- package/project/skills/pinescript-v6/SKILL.md +129 -0
- package/project/skills/pinescript-v6/reference/built-ins.md +219 -0
- package/project/skills/pinescript-v6/reference/templates/alert-webhook.pine +76 -0
- package/project/skills/pinescript-v6/reference/templates/indicator.pine +48 -0
- package/project/skills/pinescript-v6/reference/templates/strategy.pine +50 -0
- package/project/skills/pinescript-v6/reference/v5-to-v6-migration.md +102 -0
- package/project/skills/pinescript-v6/reference/v6-language.md +202 -0
- package/project/skills/stock-model-forecast/SKILL.md +192 -0
- package/project/skills/system-prompt-injection/CUSTOM_SYSTEM_PROMPT.md +333 -0
- package/project/skills/system-prompt-injection/DEFAULT_SYSTEM_PROMPT.md +327 -0
- package/project/skills/system-prompt-injection/SKILL.md +90 -0
- package/project/skills/system-prompt-injection/SYSTEM_PROMPT.md +23 -0
- package/project/skills/system-prompt-updater/SKILL.md +82 -0
- package/project/skills/system-prompt-updater/scripts/system_prompt_update.sh +106 -0
- package/project/skills/tradingview-stock-data/SKILL.md +272 -0
- package/project/src/tv_indicator/__init__.py +0 -0
- package/project/src/tv_indicator/browser/__init__.py +0 -0
- package/project/src/tv_indicator/browser/automation.py +541 -0
- package/project/src/tv_indicator/browser/selectors.py +70 -0
- package/project/src/tv_indicator/cli/__init__.py +0 -0
- package/project/src/tv_indicator/cli/browser_cmds.py +92 -0
- package/project/src/tv_indicator/cli/data_cmds.py +178 -0
- package/project/src/tv_indicator/cli/main.py +56 -0
- package/project/src/tv_indicator/cli/model_cmds.py +255 -0
- package/project/src/tv_indicator/cli/pine_cmds.py +140 -0
- package/project/src/tv_indicator/config.py +98 -0
- package/project/src/tv_indicator/data/__init__.py +0 -0
- package/project/src/tv_indicator/data/client.py +187 -0
- package/project/src/tv_indicator/data/screener.py +268 -0
- package/project/src/tv_indicator/mcp/__init__.py +0 -0
- package/project/src/tv_indicator/mcp/agent_server.py +398 -0
- package/project/src/tv_indicator/mcp/browser_server.py +133 -0
- package/project/src/tv_indicator/mcp/data_server.py +239 -0
- package/project/src/tv_indicator/model/__init__.py +19 -0
- package/project/src/tv_indicator/model/forecast.py +693 -0
- package/project/tools/import_agent_tools.sh +503 -0
- package/project/tools/install_skills.sh +673 -0
- package/project/tools/interactive_install.sh +917 -0
- package/project/tools/progress.sh +114 -0
- package/project/tools/uninstall_agent_tools.sh +373 -0
- package/src/cli.js +22 -25
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# PineScript v6 — language reference (condensed)
|
|
2
|
+
|
|
3
|
+
This is a **task-oriented** reference, not a full spec. For anything not here, see
|
|
4
|
+
TradingView's official docs at https://www.tradingview.com/pine-script-docs/.
|
|
5
|
+
|
|
6
|
+
## Script types
|
|
7
|
+
|
|
8
|
+
```pinescript
|
|
9
|
+
//@version=6
|
|
10
|
+
indicator("My Indicator", overlay=true, max_bars_back=500)
|
|
11
|
+
// or
|
|
12
|
+
strategy("My Strategy", overlay=true, initial_capital=10000, currency=currency.USD,
|
|
13
|
+
default_qty_type=strategy.percent_of_equity, default_qty_value=10,
|
|
14
|
+
commission_type=strategy.commission.percent, commission_value=0.05,
|
|
15
|
+
process_orders_on_close=true)
|
|
16
|
+
// or
|
|
17
|
+
library("MyLib", overlay=false)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Key `indicator()` / `strategy()` params:
|
|
21
|
+
- `overlay=true` → draws on the price chart; `false` → separate pane
|
|
22
|
+
- `max_bars_back=N` → how far back historical references can look (default 244; raise if you reference `close[300]` etc.)
|
|
23
|
+
- `max_lines_count`, `max_labels_count`, `max_boxes_count`, `max_polylines_count` → limits for drawing objects
|
|
24
|
+
- `precision=N` → decimal places for displayed values
|
|
25
|
+
|
|
26
|
+
## Types
|
|
27
|
+
|
|
28
|
+
| Type | Example literal | Notes |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| `int` | `42`, `na` | |
|
|
31
|
+
| `float` | `1.5`, `na` | NaN-aware: use `na(x)` not `x == na` |
|
|
32
|
+
| `bool` | `true`, `false` | |
|
|
33
|
+
| `string` | `"hello"` | Concat with `+` |
|
|
34
|
+
| `color` | `color.red`, `#FF0000`, `color.rgb(255, 0, 0, 50)` | last arg is transparency 0-100 |
|
|
35
|
+
| `series` | any of above but varies per bar | most TA outputs |
|
|
36
|
+
|
|
37
|
+
**Type qualifiers** (in order of restrictiveness):
|
|
38
|
+
- `const` → known at compile time
|
|
39
|
+
- `input` → known after script loads
|
|
40
|
+
- `simple` → fixed during the script's life
|
|
41
|
+
- `series` → may change every bar
|
|
42
|
+
|
|
43
|
+
A function expecting `simple int` cannot receive a `series int`. Common error.
|
|
44
|
+
|
|
45
|
+
## Variables
|
|
46
|
+
|
|
47
|
+
```pinescript
|
|
48
|
+
// Reassigned every bar
|
|
49
|
+
length = input.int(14, "Length", minval=1)
|
|
50
|
+
|
|
51
|
+
// Persistent across bars (initialized once)
|
|
52
|
+
var float last_high = na
|
|
53
|
+
if high > nz(last_high, 0)
|
|
54
|
+
last_high := high
|
|
55
|
+
|
|
56
|
+
// Re-initialized every bar (default)
|
|
57
|
+
ma = ta.sma(close, length)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`:=` reassigns; `=` declares.
|
|
61
|
+
|
|
62
|
+
## Conditionals & loops
|
|
63
|
+
|
|
64
|
+
```pinescript
|
|
65
|
+
// if as expression
|
|
66
|
+
trend = close > open ? "up" : "down"
|
|
67
|
+
|
|
68
|
+
// if as statement
|
|
69
|
+
if close > open
|
|
70
|
+
label.new(bar_index, high, "up")
|
|
71
|
+
else if close < open
|
|
72
|
+
label.new(bar_index, low, "down")
|
|
73
|
+
|
|
74
|
+
// for
|
|
75
|
+
sum = 0.0
|
|
76
|
+
for i = 0 to length - 1
|
|
77
|
+
sum += close[i]
|
|
78
|
+
avg = sum / length
|
|
79
|
+
|
|
80
|
+
// while
|
|
81
|
+
i = 0
|
|
82
|
+
while i < 10 and close[i] > 0
|
|
83
|
+
i += 1
|
|
84
|
+
|
|
85
|
+
// for...in (arrays)
|
|
86
|
+
arr = array.from(1, 2, 3, 4)
|
|
87
|
+
total = 0
|
|
88
|
+
for v in arr
|
|
89
|
+
total += v
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Functions
|
|
93
|
+
|
|
94
|
+
```pinescript
|
|
95
|
+
// User-defined function
|
|
96
|
+
my_avg(src, len) =>
|
|
97
|
+
sum = 0.0
|
|
98
|
+
for i = 0 to len - 1
|
|
99
|
+
sum += src[i]
|
|
100
|
+
sum / len
|
|
101
|
+
|
|
102
|
+
// With explicit parameter types
|
|
103
|
+
weighted(simple int len, series float src) =>
|
|
104
|
+
ta.wma(src, len)
|
|
105
|
+
|
|
106
|
+
// Method-style on user types (v6)
|
|
107
|
+
type Point
|
|
108
|
+
float x
|
|
109
|
+
float y
|
|
110
|
+
|
|
111
|
+
method dist(Point self, Point other) =>
|
|
112
|
+
math.sqrt(math.pow(self.x - other.x, 2) + math.pow(self.y - other.y, 2))
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Collections
|
|
116
|
+
|
|
117
|
+
```pinescript
|
|
118
|
+
// Array
|
|
119
|
+
var float[] highs = array.new<float>(0)
|
|
120
|
+
array.push(highs, high)
|
|
121
|
+
if array.size(highs) > 100
|
|
122
|
+
array.shift(highs)
|
|
123
|
+
|
|
124
|
+
// Or with the literal form
|
|
125
|
+
nums = array.from(1.0, 2.0, 3.0)
|
|
126
|
+
|
|
127
|
+
// Map (v5+)
|
|
128
|
+
var map<string, float> levels = map.new<string, float>()
|
|
129
|
+
map.put(levels, "support", 100.0)
|
|
130
|
+
support = map.get(levels, "support")
|
|
131
|
+
|
|
132
|
+
// Matrix
|
|
133
|
+
var m = matrix.new<float>(3, 3, 0.0)
|
|
134
|
+
matrix.set(m, 0, 0, 1.0)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Multi-timeframe data (`request.security`)
|
|
138
|
+
|
|
139
|
+
```pinescript
|
|
140
|
+
// CORRECT — explicit lookahead off, no repaint
|
|
141
|
+
htf_close = request.security(syminfo.tickerid, "1D", close,
|
|
142
|
+
lookahead=barmerge.lookahead_off)
|
|
143
|
+
|
|
144
|
+
// To get confirmed HTF values without repainting, offset by [1]
|
|
145
|
+
htf_close_confirmed = request.security(syminfo.tickerid, "1D", close[1],
|
|
146
|
+
lookahead=barmerge.lookahead_on)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Rule of thumb: **`lookahead_off` (no offset)** OR **`lookahead_on` with `[1]` offset**.
|
|
150
|
+
Anything else likely repaints.
|
|
151
|
+
|
|
152
|
+
## Drawing
|
|
153
|
+
|
|
154
|
+
```pinescript
|
|
155
|
+
plot(close, "Close", color=color.blue, linewidth=2)
|
|
156
|
+
plotshape(ta.crossover(close, ta.sma(close, 20)), "Buy",
|
|
157
|
+
shape.triangleup, location.belowbar, color.green, size=size.small)
|
|
158
|
+
bgcolor(close > open ? color.new(color.green, 90) : color.new(color.red, 90))
|
|
159
|
+
hline(0, "Zero", color=color.gray, linestyle=hline.style_dashed)
|
|
160
|
+
|
|
161
|
+
// Dynamic objects
|
|
162
|
+
if barstate.islast
|
|
163
|
+
label.new(bar_index, high, "HIGH", color=color.yellow, textcolor=color.black)
|
|
164
|
+
line.new(bar_index - 10, low, bar_index, low, color=color.red, width=2)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Alerts
|
|
168
|
+
|
|
169
|
+
```pinescript
|
|
170
|
+
// Static condition (legacy)
|
|
171
|
+
alertcondition(ta.crossover(close, ta.sma(close, 20)), "Crossover")
|
|
172
|
+
|
|
173
|
+
// Dynamic alert with message — preferred for webhook integration
|
|
174
|
+
if ta.crossover(close, ta.sma(close, 20))
|
|
175
|
+
alert('{"action":"buy","symbol":"' + syminfo.ticker + '","price":' +
|
|
176
|
+
str.tostring(close) + '}', alert.freq_once_per_bar_close)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Strategy alerts (use placeholders in the alert dialog):
|
|
180
|
+
- `{{strategy.order.action}}` → "buy" / "sell"
|
|
181
|
+
- `{{strategy.order.contracts}}` → size
|
|
182
|
+
- `{{strategy.position_size}}`
|
|
183
|
+
- `{{ticker}}`, `{{close}}`, `{{time}}`
|
|
184
|
+
|
|
185
|
+
## Bar states
|
|
186
|
+
|
|
187
|
+
| State | True when |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `barstate.isfirst` | First bar in the dataset |
|
|
190
|
+
| `barstate.islast` | Most recent bar (real-time chart tip) |
|
|
191
|
+
| `barstate.isconfirmed` | Bar has closed |
|
|
192
|
+
| `barstate.isnew` | New bar just opened |
|
|
193
|
+
| `barstate.isrealtime` | Live bar (not historical) |
|
|
194
|
+
| `barstate.islastconfirmedhistory` | Last historical bar before live |
|
|
195
|
+
|
|
196
|
+
## Common pitfalls
|
|
197
|
+
|
|
198
|
+
1. **Repainting**: any value that changes after a bar closes. Caused by `request.security` lookahead, `barstate.islast`-only logic, `var` with conditional init.
|
|
199
|
+
2. **Look-ahead bias in backtests**: using `high`/`low` of the *current* bar in entry logic is fine in Pine but unrealistic if `calc_on_every_tick=true`.
|
|
200
|
+
3. **`na` propagation**: `na + 1 == na`. Wrap with `nz(x, 0)` to default.
|
|
201
|
+
4. **String concatenation type errors**: must convert with `str.tostring(num)`.
|
|
202
|
+
5. **`max_bars_back` errors**: if you reference `close[300]` and `max_bars_back=244` (default), you get an error. Bump it.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: stock-model-forecast
|
|
3
|
+
description: Trigger or ingest the server-side Indicator xs_range model forecast and same-day analysis artifact workflow for stock-like instruments only. Use when equity/ETF/listed-fund/index-style analysis should include the 20-trading-day model forecast, when checking or writing temp/{YYYYMMDD_HHMMSS}/{target-id}/analyzed_result.md, or when the user asks for model forecast, predicted range, low_20d/high_20d, fair_value, value_gap, win-rate, IoU, or L/S rank.
|
|
4
|
+
compatibility: Generic Agent Skill. Works with Pi, Claude Code, Codex-style agents, Gemini CLI, Cursor, and other agents that can run shell commands or call MCP tools.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Stock Model Forecast Skill
|
|
8
|
+
|
|
9
|
+
Use this skill to include the server-side xs_range model forecast in stock-like reports.
|
|
10
|
+
|
|
11
|
+
The model applies to equities, ETFs/listed funds, and index proxies. It is not the default model for crypto, forex, futures, commodities contracts, or perpetual pairs such as `BINANCE:BTCUSDT`.
|
|
12
|
+
|
|
13
|
+
The model runs on a server. Indicator only calls the API and normalizes the response:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
training-view model forecast <SYMBOL>
|
|
17
|
+
make model-forecast SYMBOL=<SYMBOL>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The client expects `TV_MODEL_API_URL` to point at the forecast endpoint. It sends a JSON body with `symbol`, `model_ticker`, `refresh`, and `period`. If `TV_MODEL_API_KEY` or `TV_MODEL_API_TOKEN` is set, it is sent as a bearer token. `REFRESH=1` / `--refresh` asks the server to recompute before returning a row when the API supports it.
|
|
21
|
+
|
|
22
|
+
## When to load
|
|
23
|
+
|
|
24
|
+
Load this skill when:
|
|
25
|
+
|
|
26
|
+
- A stock-like equity/ETF/listed-fund/index report should attempt the model forecast as part of the active market-analysis workflow.
|
|
27
|
+
- An analyze-style request needs to check same-day `temp/{YYYYMMDD}_*/{TARGET_ID}/analyzed_result.md` before calling the model API.
|
|
28
|
+
- The user asks for "model forecast", "20d forecast", "predicted range", `xs_range`, `low_20d`, `high_20d`, `fair_value`, `value_gap`, win-rate, IoU, or L/S rank.
|
|
29
|
+
|
|
30
|
+
Do not load or call this model just because the user asks for crypto, forex, futures, or commodity-contract analysis. For those instruments, record `Model forecast not applicable: xs_range model is stock/ETF/index-only` in the analysis artifact and continue with TradingView market data, news, asset metrics, and PineScript-compatible technicals. If the user explicitly asks to test the model command on an unsupported symbol, it should return a not-applicable result rather than calling the API.
|
|
31
|
+
|
|
32
|
+
## Configuration
|
|
33
|
+
|
|
34
|
+
Required:
|
|
35
|
+
|
|
36
|
+
```env
|
|
37
|
+
TV_MODEL_API_URL=https://model.example/forecast
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Optional:
|
|
41
|
+
|
|
42
|
+
```env
|
|
43
|
+
TV_MODEL_API_KEY=...
|
|
44
|
+
TV_MODEL_API_TOKEN=...
|
|
45
|
+
TV_MODEL_API_STATUS_URL=https://model.example/status
|
|
46
|
+
TV_MODEL_API_TIMEOUT=60
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Use `api-credential-storage` to save these values when the user provides them. Never print API keys or tokens.
|
|
50
|
+
|
|
51
|
+
## Ticker normalization
|
|
52
|
+
|
|
53
|
+
The client normalizes common TradingView/Yahoo-style inputs before sending them to the API:
|
|
54
|
+
|
|
55
|
+
| User / TV symbol | Model ticker |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `TSLA`, `NASDAQ:TSLA` | `TSLA` |
|
|
58
|
+
| `AAPL`, `NASDAQ:AAPL` | `AAPL` |
|
|
59
|
+
| `SPX`, `^GSPC` | `SPX` |
|
|
60
|
+
| `TWSE:0050`, `0050.TW` | `0050` |
|
|
61
|
+
| `TPEX:6584`, `6584.TWO` | `6584` |
|
|
62
|
+
| `BINANCE:BTCUSDT`, `BTC-USD` | unsupported by default |
|
|
63
|
+
|
|
64
|
+
Supported stock-like tickers that are new to the server should be handled by the server-side dynamic/unseen-symbol path. Do not describe a stock-like symbol as fundamentally outside model coverage unless the API returns that limitation or no usable row.
|
|
65
|
+
|
|
66
|
+
## Installation / verification commands
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
make install # installs the API client and prepares temp/
|
|
70
|
+
make model-status # show forecast API configuration/status
|
|
71
|
+
make model-setup # validate forecast API configuration
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Preferred command
|
|
75
|
+
|
|
76
|
+
From Indicator repo:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
make model-forecast SYMBOL=NASDAQ:TSLA
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Equivalent CLI:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
conda run -n tv-indicator --live-stream --no-capture-output \
|
|
86
|
+
training-view model forecast NASDAQ:TSLA
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
JSON for machine parsing:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
conda run -n tv-indicator --live-stream --no-capture-output \
|
|
93
|
+
training-view model forecast NASDAQ:TSLA --json
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Refresh/recompute first when the server supports it:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
make model-forecast SYMBOL=NASDAQ:TSLA REFRESH=1 MODEL_JSON=1
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
MCP-aware agents can call `training-view-data:model_forecast` with `symbol`, `refresh`, and `period`.
|
|
103
|
+
|
|
104
|
+
## Output payload
|
|
105
|
+
|
|
106
|
+
`training-view model forecast ... --json` returns the same compact contract agents should parse:
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"ok": true,
|
|
111
|
+
"symbol": "NASDAQ:TSLA",
|
|
112
|
+
"model_ticker": "TSLA",
|
|
113
|
+
"covered": true,
|
|
114
|
+
"model_applicable": true,
|
|
115
|
+
"model_api_url": "https://model.example/forecast",
|
|
116
|
+
"model_output": {
|
|
117
|
+
"ticker": "TSLA",
|
|
118
|
+
"class": "US_STOCK",
|
|
119
|
+
"position": "NEUTRAL",
|
|
120
|
+
"rank": 10,
|
|
121
|
+
"close": 123.45,
|
|
122
|
+
"low_20d": 111.11,
|
|
123
|
+
"high_20d": 140.0,
|
|
124
|
+
"fair_value": 124.72,
|
|
125
|
+
"value_gap": 1.03,
|
|
126
|
+
"signal": "FAIR",
|
|
127
|
+
"mean_iou": 0.52,
|
|
128
|
+
"iou60": 0.4,
|
|
129
|
+
"dir_win": 0.56
|
|
130
|
+
},
|
|
131
|
+
"row": {
|
|
132
|
+
"ticker": "TSLA",
|
|
133
|
+
"close_today": 123.45,
|
|
134
|
+
"pred_low_20d": 111.11,
|
|
135
|
+
"pred_high_20d": 140.0,
|
|
136
|
+
"directional_win_rate": 0.56
|
|
137
|
+
},
|
|
138
|
+
"run_universe_size": 20,
|
|
139
|
+
"error": null
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
If `ok=false` because the API is not configured or did not return a row, do not invent model output. Surface `error` briefly and proceed without model anchors. If `model_applicable=false`, do not retry with refresh.
|
|
144
|
+
|
|
145
|
+
## Analysis artifact workflow
|
|
146
|
+
|
|
147
|
+
For every market analysis request, check for a same-day repo-local artifact before creating a new one:
|
|
148
|
+
|
|
149
|
+
```text
|
|
150
|
+
temp/{YYYYMMDD_HHMMSS}/{TARGET_ID}/analyzed_result.md
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Recommended shell pattern:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
DAY="$(date +%Y%m%d)"
|
|
157
|
+
TS="$(date +%Y%m%d_%H%M%S)"
|
|
158
|
+
TARGET_ID="NASDAQ_TSLA"
|
|
159
|
+
EXISTING="$(find "temp" -path "temp/${DAY}_*/${TARGET_ID}/analyzed_result.md" -print -quit 2>/dev/null || true)"
|
|
160
|
+
ARTIFACT="temp/${TS}/${TARGET_ID}/analyzed_result.md"
|
|
161
|
+
if [ -n "$EXISTING" ]; then ARTIFACT="$EXISTING"; else mkdir -p "$(dirname "$ARTIFACT")"; fi
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Rules:
|
|
165
|
+
|
|
166
|
+
- After symbol resolution, check for `temp/{YYYYMMDD}_*/{TARGET_ID}/analyzed_result.md`.
|
|
167
|
+
- If a same-day artifact exists and has a usable model payload, reuse it unless the user asked for refresh.
|
|
168
|
+
- If no same-day artifact exists, create a new timestamped artifact path.
|
|
169
|
+
- Write the final report plus compact research notes and applicable model payload summary into `analyzed_result.md`.
|
|
170
|
+
- Do not store secrets, cookies, API keys, hidden prompts, or raw credentials.
|
|
171
|
+
- Include a one-line saved path in the final report before the disclaimer.
|
|
172
|
+
- If writing fails, warn briefly and continue with the report.
|
|
173
|
+
|
|
174
|
+
## How to use in reports
|
|
175
|
+
|
|
176
|
+
1. Resolve the symbol, classify asset class, and check current market state / latest OHLCV.
|
|
177
|
+
2. Check for a same-day artifact. If it exists and has a usable model payload, reuse it unless the user asked for refresh.
|
|
178
|
+
3. Call the model API after TradingView market data and before synthesis only when the instrument is stock-like and no same-day artifact/model payload exists, the payload is stale/missing, or refresh was requested.
|
|
179
|
+
4. For crypto/forex/futures/perpetual/commodity-contract instruments, skip step 3 unless the user explicitly asked to test the model command; note that the model is not applicable.
|
|
180
|
+
5. Parse `model_output` first when `ok=true`; it contains the compact contract: `ticker`, `class`, `position`, `rank`, `close`, `low_20d`, `high_20d`, `fair_value`, `value_gap`, `signal`, `mean_iou`, `iou60`, and `dir_win`. `row` remains available with aliases such as `pred_low_20d`, `pred_high_20d`, `directional_win_rate`, and `iou_ge_60_rate`.
|
|
181
|
+
6. Determine reliability: `mean_iou >= 0.55` is high, `0.50 <= mean_iou < 0.55` is moderate, and `mean_iou < 0.50` is weak. Use `dir_win > 0.55` as a usable direction signal and ignore direction when `dir_win < 0.50`.
|
|
182
|
+
7. Reconcile with technicals and news. Reliable `high_20d` can anchor TP2 near resistance; reliable `low_20d` can anchor SL/invalidation near support. If model direction conflicts with technicals/news, state the conflict explicitly.
|
|
183
|
+
8. Write the final report and compact notes into the analysis artifact.
|
|
184
|
+
9. In the Short Report, include the forecast range only when a row is applicable and available.
|
|
185
|
+
|
|
186
|
+
## Rules
|
|
187
|
+
|
|
188
|
+
- Never fabricate model output or historical accuracy.
|
|
189
|
+
- Do not use predicted prices without also citing `mean_iou` or win-rate context.
|
|
190
|
+
- If the API fails for a supported stock-like instrument, include the API failure summary and continue without model anchors.
|
|
191
|
+
- The model horizon is 20 trading days. For intraday or 1-5 day requests, use the model only as broad bias/range context.
|
|
192
|
+
- A `SHORT` basket with `UP` direction means expected absolute rise but relative underperformance versus the current run universe; flag this as relative-value context.
|