Skip to main content
ClaudeWave
Skill12k estrellas del repoactualizado today

pine-script

# pine-script This Claude Code skill translates trading strategies from the Vibe-Trading backtesting framework into executable code for five major platforms: TradingView (Pine Script v6), Chinese brokers (TDX Formula for 通达信, 同花顺, 东方财富), and MetaTrader 5 (MQL5). Use this skill to export a validated backtest strategy to all platforms simultaneously, generating a unified output file with platform-specific code blocks and deployment instructions for each venue.

Instalar en Claude Code
Copiar
git clone --depth 1 https://github.com/HKUDS/Vibe-Trading /tmp/pine-script && cp -r /tmp/pine-script/agent/src/skills/pine-script ~/.claude/skills/pine-script
Después abre una sesión nueva de Claude Code; el skill carga automáticamente.

SKILL.md

## Overview

This skill exports a Vibe-Trading strategy to **all major trading platforms** in one go.
Output file: `artifacts/strategy.pine` (inside the run directory).

Supported platforms (always generate ALL):

| Group | Platforms | Language |
|-------|-----------|----------|
| International Charts | TradingView | Pine Script v6 |
| China Equities | 通达信 / 同花顺 / 东方财富 | TDX Formula |
| Forex / CFD | MetaTrader 5 | MQL5 |

## Workflow: Export from Backtest

1. `load_skill("pine-script")` — read this guide
2. `read_file("config.json")` — understand instruments, dates, parameters
3. `read_file("code/signal_engine.py")` — understand the Python strategy logic
4. **Translate** the strategy to ALL platforms using the references below
5. `write_file("artifacts/strategy.pine")` — save the combined output
6. Return the code in a code block with usage instructions per platform

## Workflow: Generate from Description

1. `load_skill("pine-script")` — read this guide
2. Write indicator/strategy code for ALL platforms based on the user's description
3. `write_file("artifacts/strategy.pine")` — save the combined output
4. Return the code with usage instructions

## Output Format

The output file uses this structure (all platforms in one file):

```
================================================================================
  TRADINGVIEW — Pine Script v6
  Paste into: Pine Editor → New blank indicator → Add to Chart
================================================================================

[Pine Script code here]

================================================================================
  通达信 / 同花顺 / 东方财富 (TDX Formula)
  Paste into: 功能 → 公式管理器 → 新建指标公式
================================================================================

[TDX formula code here]

================================================================================
  MT5 — MQL5
  Save as: .mq5 file → MetaEditor → Compile → Navigator → Attach to Chart
================================================================================

[MQL5 code here]

```

---

# Platform Reference

## 1. TradingView — Pine Script v6

### Template

```pinescript
// This strategy was generated by Vibe-Trading
// Paste into TradingView Pine Editor → Add to Chart
//@version=6
strategy("Strategy Name", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, initial_capital=1000000)

// ============================================================================
// INPUTS
// ============================================================================
// [Group inputs logically with input.int(), input.float(), input.string()]

// ============================================================================
// CALCULATIONS
// ============================================================================
// [Core indicator calculations]

// ============================================================================
// CONDITIONS
// ============================================================================
longCondition = false
shortCondition = false
exitLongCondition = false
exitShortCondition = false

// ============================================================================
// STRATEGY EXECUTION
// ============================================================================
if longCondition
    strategy.entry("Long", strategy.long)
if shortCondition
    strategy.entry("Short", strategy.short)
if exitLongCondition
    strategy.close("Long")
if exitShortCondition
    strategy.close("Short")

// ============================================================================
// PLOTS
// ============================================================================
// [Visual overlays: moving averages, bands, signals]

// ============================================================================
// ALERTS
// ============================================================================
alertcondition(longCondition, title="Long Signal", message="Long entry signal triggered")
alertcondition(shortCondition, title="Short Signal", message="Short entry signal triggered")
```

### Python → Pine Script Mapping

| Python (pandas/numpy) | Pine Script v6 |
|------------------------|----------------|
| `df['close'].rolling(n).mean()` | `ta.sma(close, n)` |
| `df['close'].ewm(span=n).mean()` | `ta.ema(close, n)` |
| `ta.RSI(df['close'], n)` or manual RSI | `ta.rsi(close, n)` |
| `ta.MACD(df['close'])` | `[macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9)` |
| `df['close'].rolling(n).std()` | `ta.stdev(close, n)` |
| `df['high'].rolling(n).max()` | `ta.highest(high, n)` |
| `df['low'].rolling(n).min()` | `ta.lowest(low, n)` |
| `df['close'].pct_change()` | `(close - close[1]) / close[1]` |
| `df['volume'].rolling(n).mean()` | `ta.sma(volume, n)` |
| `df['close'] > df['close'].shift(1)` | `close > close[1]` |
| Bollinger Bands | `[mid, upper, lower] = ta.bb(close, length, mult)` |
| ATR | `ta.atr(length)` |
| ADX | `ta.adx(high, low, close, length)` |
| Stochastic | `ta.stoch(close, high, low, length, smoothK, smoothD)` |
| CCI | `ta.cci(close, length)` |
| Williams %R | `ta.wpr(length)` |
| MFI | `ta.mfi(close, length)` |
| OBV | `ta.obv` |
| VWAP | `ta.vwap` |

### Data References

| Python | Pine Script v6 |
|--------|----------------|
| `df['open']` | `open` |
| `df['high']` | `high` |
| `df['low']` | `low` |
| `df['close']` | `close` |
| `df['volume']` | `volume` |
| `df.index` (datetime) | `time` |
| `df['close'].shift(n)` | `close[n]` |

### Signal Logic

| Python Pattern | Pine Script v6 |
|---------------|----------------|
| `(fast > slow) & (fast.shift(1) <= slow.shift(1))` | `ta.crossover(fast, slow)` |
| `(fast < slow) & (fast.shift(1) >= slow.shift(1))` | `ta.crossunder(fast, slow)` |
| `signal.where(condition, 0)` | `condition ? value : 0` |
| `np.where(cond, val_true, val_false)` | `cond ? val_true : val_false` |
| `signal.clip(-1, 1)` | `math.
vibe-tradingSkill

Professional finance research toolkit — backtesting (7 engines + benchmark comparison panel), factor analysis, Alpha Zoo (452 pre-built alphas across qlib158/alpha101/gtja191/academic), options pricing, 77 finance skills, 29 multi-agent swarm teams, Trade Journal analyzer, and Shadow Account (extract → backtest → render) across 7 data sources (tushare, yfinance, okx, akshare, mootdx, ccxt, futu).

adr-hshareSkill

ADR/H-share/A-share cross-listing premium analysis — track pricing gaps between US-listed ADRs, HK-listed H-shares, and A-shares for arbitrage signals, dual-listing valuation, and delisting risk assessment.

akshareSkill

AKShare financial data aggregator (18k+ stars). Free, no API key. Covers A-shares, US, HK, futures, macro, forex. Primary fallback for tushare and yfinance.

alpha-zooSkill

Browse and bench the bundled alpha zoos — prebuilt cross-sectional factor libraries (Kakushadze 101, GTJA 191, Qlib 158, Fama-French / Carhart). Use when the user asks "which alphas exist", wants metadata on a named alpha, or wants to run IC/IR on a whole zoo over a universe.

ashare-pre-st-filterSkill

A 股 ST/*ST 风险预测框架 — 基于最新中报/三季报或业绩预告/快报,预测下一财年是否会因营收、利润、净资产、分红不达标而被风险警示,并将新浪监管处罚记录作为独立证据面纳入风险等级。仅适用于 A 股,不预测财务造假。

asset-allocationSkill

Asset allocation theory and optimizer usage — MPT / Black-Litterman / risk budgeting / all-weather strategy, including guides for 4 optimizers and rebalancing rules.

backtest-diagnoseSkill

Diagnose failed or underperforming backtests, locate the root cause, and fix the issue

behavioral-financeSkill

Behavioral finance applications: theories of overreaction and underreaction, behavioral explanations for momentum and reversal, investor sentiment cycles, cognitive-bias checklists, and debiasing quantitative strategies.