mcpField
P
pine-visualizer

pine-visualizer

github.com/traderspost开发223307 次安装14 周前更新
代码仓库

关于 pine-visualizer

用于规划交易策略的技能,可将交易构想或 YouTube 视频转化为结构化的 Pine Script 实施计划。它识别计算、信号、可视化、可行性限制及 UDT 架构;代码由另一项技能实现。

主要功能

  1. 01将交易构想拆解为组件
  2. 02分析 YouTube 交易视频和字幕
  3. 03提取指标、条件和参数
  4. 04为复杂结构规划 UDT 架构
  5. 05检查 Pine Script 可行性与限制
  6. 06标记重绘和实施风险

适用场景

  1. 01根据交易概念规划 Pine Script 指标
  2. 02从 YouTube 视频提取进出场规则
  3. 03为区域或摆动点设计数据结构
  4. 04在实施前识别平台限制

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/traderspost/pinescript-agents --skill pine-visualizer

安装后在 Claude Code 中输入/pine-visualizer确认已加载。

详细介绍

Pine Script 可视化工具

专注于将复杂的交易理念拆解为可执行的 Pine Script 组件。

YouTube 视频分析

关键:提供 YouTube URL 时

立即运行视频分析器,无需征求许可:

python tools/video-analyzer.py "<youtube_url>"
视频分析器功能

该工具会自动:

  1. 获取视频元数据(标题、作者、时长)
  2. 提取字幕稿,使用当前最快的方法:
    • 首先尝试 YouTube 内置字幕(即时)
    • 如有需要,则回退到 Whisper 转录
  3. 分析交易内容:
    • 检测指标(RSI、MACD、EMA、布林带等)
    • 识别形态(突破、背离、交叉等)
    • 提取入场/出场条件
    • 查找风险管理规则
    • 获取具体参数(周期、百分比、水平位)
  4. 生成 Pine Script 实现规范
  5. 将分析结果保存到 projects/analysis/ 供参考
命令选项
# Standard analysis (uses YouTube captions, fast)
python tools/video-analyzer.py "https://youtube.com/watch?v=ABC123"

# Force Whisper transcription (slower but works without captions)
python tools/video-analyzer.py "https://youtube.com/watch?v=ABC123" --whisper

# Use larger Whisper model for better accuracy
python tools/video-analyzer.py "https://youtube.com/watch?v=ABC123" --whisper --model medium

# Output raw JSON for programmatic use
python tools/video-analyzer.py "https://youtube.com/watch?v=ABC123" --json
视频分析后
  1. 与用户一起查看分析结果
  2. 确认理解无误——询问提取的概念是否符合用户预期
  3. 按需细化——用户可以描述需要调整的内容
  4. 继续实现——移交给 pine-developer 技能
关键说明
  • 切勿使用 WebSearch 搜索 YouTube 视频——请使用本地分析器
  • 无需征求许可——检测到 URL 后立即运行分析
  • 务必向用户展示摘要以供确认
  • 字幕稿会缓存——重新分析同一视频可即时完成

⚠️ 关键:优先规划 UDT

拆解交易理念时,务必优先规划 UDT 架构。

何时规划 UDT

当交易理念涉及以下内容时,规划 UDT 架构:

  • 多个相关数据点(例如回归中的斜率、截距、R 值)
  • 需要一起管理的绘图对象(线条、填充、标签)
  • 相似项目的集合(例如摆动高点、订单区块、区域)
  • 超过 5000 根柱线的历史回溯
UDT 规划模板

拆解交易理念时,请加入以下部分:

UDT ARCHITECTURE:
1. Type Definition
   - What fields does each instance need?
   - Include time + bar_index for coordinates
   - Include drawing objects as fields

2. Storage
   - Single var array for collection
   - Named instances for special cases (original, live, current)

3. Methods
   - delete(): Clean up drawing objects
   - draw(): Create visuals using xloc.bar_time
   - calculateY(): If line-based calculations needed

4. Coordinate Strategy
   - Store TIME when events occur (for unlimited lookback drawing)
   - Store bar_index for Y calculations (slope * bar + intercept)
示例:规划摆动高点检测器

用户请求:“创建一个标记摆动高点并从这些高点绘制水平位的指标”

优先使用 UDT 的拆解:

UDT ARCHITECTURE:
1. Type Definition:
   type SwingHigh
       int detectedTime      // When swing was detected
       int detectedBar       // For Y calculations
       float price           // The high price
       int confirmedTime     // When confirmed
       line levelLine = na   // Horizontal level from swing
       label marker = na     // Label marking the swing

2. Storage:
   var array<SwingHigh> swingHighs = array.new<SwingHigh>()
   var SwingHigh currentPending = na  // Unconfirmed swing

3. Methods:
   method delete(SwingHigh this) =>
       if not na(this.levelLine)
           line.delete(this.levelLine)
       if not na(this.marker)
           label.delete(this.marker)

   method draw(SwingHigh this, color lineColor) =>
       this.delete()
       // Use xloc.bar_time for unlimited lookback!
       this.levelLine := line.new(this.detectedTime, this.price,
            time, this.price, xloc=xloc.bar_time, ...)
       this.marker := label.new(this.detectedTime, this.price,
            "SH", xloc=xloc.bar_time, ...)

4. Coordinate Strategy:
   When swing detected:
       capturedTime := time        // For drawing
       capturedBar := bar_index    // For calculations
及早指出的反模式

分析交易理念时,请指出以下问题:

如果理念涉及……指出此问题……建议改用……
多个相关值不要使用并行数组使用单个 UDT 数组
历史绘图bar_index 有 5000 的限制使用 xloc.bar_time
重复绘图代码违反 DRY 原则使用 UDT draw() 方法
手动删除线条容易出错使用 UDT delete() 方法

Pine Script v6 2025 年规划注意事项

分析和规划实现方案时,请考虑以下 2025 年的重要更新:

及早指出的破坏性变更

2025 年 3 月:集合请使用 for...in 规划基于循环的实现(订单区块、摆动检测、形态扫描)时:

// ✅ BEST: Use for...in for arrays (safe, clean, preferred)
for element in myArray
    // Process element directly - no boundary issues

// ✅ BEST: With index when needed (e.g., order blocks, swing points)
for [index, element] in myArray
    // Have both index and value

// ✅ Works with matrices and maps too
for [key, value] in myMap
    // Process key-value pairs

// ⚠️ FALLBACK: If traditional for needed, cache boundary
arrSize = array.size(arr)  // MUST cache before loop
for i = 0 to arrSize - 1
    // Process...

行续接规则(2025 年 12 月)

  • 括号内:现在可使用任意缩进
  • 括号外:仍需使用非 4 的倍数缩进
  • 三元运算符:必须保持在同一行
拓展可能性的新功能

输入参数 active(2025 年 7 月) 规划用户输入时,建议使用条件可见性:

  • “高级模式”开关,用于显示更多设置
  • 特定策略模式的输入项(仅在选择相关模式时显示)
  • 仅在启用“显示视觉元素”时显示的视觉设置

绘图线型(2025 年 9 月) 规划可视化时,建议通过线型区分内容:

  • 主要信号:实线
  • 次要信号/预测信号:虚线
  • 目标/水平线:点线

更长的字符串(2025 年 8 月:40,960 个字符) 现在可以制作更全面的信息面板和报告:

  • 详细的策略报告
  • 多部分分析表
  • 扩展的工具提示信息

不限数量的作用域(2025 年 2 月) 现在可以实现复杂的嵌套逻辑:

  • 深度嵌套的类型方法
  • 复杂的多条件评估
  • 更模块化的函数设计
可行性评估更新

评估可实现的功能时,请纳入以下内容:

功能2025 年状态规划备注
复杂循环✅ 可实现缓存边界,避免无限循环
条件输入✅ 原生支持使用 active 参数
视觉层次✅ 已增强使用 linestyle 区分
长报告✅ 40K 字符可制作全面的表格
深度嵌套✅ 不限无 550 个作用域限制
Tick 数据⚠️ 受限bid/ask 仅适用于 1T 时间周期
组件规划清单

拆解想法时,请确认以下事项:

UDT 架构(优先检查!)

  • 为复杂数据结构定义 UDT 类型
  • 坐标同时存储时间和 bar_index
  • 将绘图对象纳入 UDT 字段
  • 规划 delete() 和 draw() 方法
  • 使用单个 UDT 数组,而非多个并行数组
  • 为历史绘图规划 xloc.bar_time

代码质量

  • 基于循环的逻辑使用 for...in(优先)或缓存边界
  • 使用 active 参数对条件输入进行分组
  • 视觉元素具有样式层次
  • 字符串输出不超过 40K 字符限制
  • 作用域复杂度合理(但不受限制)

核心职责

想法拆解
  • 将交易概念拆分为离散且可实现的任务
  • 找出所有必需的计算、指标和逻辑流程
  • 将抽象想法映射到具体的 Pine Script 功能
  • 制定清晰的实施路线图
  • 标记影响实施的 2025 年注意事项
组件识别
  • 确定所需的内置指标
  • 找出所需的自定义计算
  • 指定数据输入和输出
  • 定义可视化要求(绘图、标签、表格)
工作流规划
  • 制定合理的实施顺序
  • 找出组件之间的依赖关系
  • 预判潜在挑战
  • 必要时建议替代方案
Pine Script 可行性分析
  • 验证想法能否在 Pine Script 的限制范围内实现
  • 找出 TradingView 平台限制
  • 为限制提出变通方案
  • 尽早标记潜在的重绘问题

工作流程

对于概念性问题
  1. 仔细听取用户的交易想法
  2. 如有需要,提出澄清问题
  3. 将想法拆分为以下内容:
    • 所需的输入参数
    • 所需的计算
    • 逻辑条件
    • 输出/显示要求
    • 警报条件(如适用)
  4. 制定结构化的实施计划
  5. 使用 TodoWrite 记录所有任务
  6. 确定由哪些技能负责实施
对于 YouTube 视频
  1. 检测到 URL 后,立即运行视频分析器
  2. 向用户显示分析摘要
  3. 确认理解是否一致——“这符合您的需求吗?”
  4. 根据需要进行调整——用户可以修改或澄清
  5. 根据确认后的分析制定实施计划
  6. 交由 pine-developer 进行代码实现

输出格式

对于概念分析
CONCEPT SUMMARY:
[Brief restatement of the trading idea]

UDT ARCHITECTURE:
Type: [Name]
Fields:
  - int startTime, endTime     // For xloc.bar_time drawing
  - int startBar, endBar       // For Y calculations
  - [data fields]              // Core data
  - line/box/label [name] = na // Drawing objects

Storage:
  - var array<[Type]> items = array.new<[Type]>()
  - var [Type] current = na    // If needed

Methods:
  - delete() - cleanup drawings
  - draw() - create visuals with xloc.bar_time
  - [custom methods]

COMPONENTS NEEDED:
1. [Component 1]
2. [Component 2]
...

IMPLEMENTATION STEPS:
1. Define UDT type with all fields
2. Add UDT methods (delete, draw, etc.)
3. [Additional steps]
...

POTENTIAL CHALLENGES:
- [Challenge 1]
- [Challenge 2]

REQUIRED RESOURCES:
- [Template or utility to use]
视频分析

视频分析器会输出一份格式化摘要,其中包括:

  • 视频来源信息
  • 检测到的脚本类型(指标/策略)
  • 复杂度评分(1-10)
  • 找到的主要指标和形态
  • 提取的入场/出场条件
  • 建议的功能
  • 实现说明

关键注意事项(2025 年更新)

平台限制
  • Pine Script v6 的语法和功能(2025 年更新)
  • TradingView 的 500 根 K 线回溯限制
  • 最多 500 个绘图输出
  • 最多 40 次 security() 调用
  • 编译后的脚本大小上限为 100KB
  • 字符串:最多 40,960 个字符(2025 年 8 月增加)
  • 作用域:无限(2025 年 2 月取消限制)
执行模型
  • 防止重绘的策略
  • 实时与历史计算的差异
  • 警报系统限制
  • bid/ask 仅在 1T 时间周期可用(2025 年 2 月)
语法注意事项
  • for 循环边界会在每次迭代时重新计算(2025 年 3 月)
  • 换行规则(括号内灵活,括号外严格)
  • 三元运算符必须保持在同一行

示例:概念拆解

用户:“我想要一个价格上穿 50 EMA 且 RSI 处于超卖状态时买入的策略”

回复:

CONCEPT SUMMARY:
Long entry strategy using EMA crossover with RSI filter

UDT ARCHITECTURE:
(Simple strategy - UDT not required for this use case.
UDTs are best for: swing points, order blocks, zones, regressions, etc.)

COMPONENTS NEEDED:
1. 50-period EMA calculation
2. RSI calculation with oversold threshold
3. Price crossover detection
4. Entry condition logic
5. Strategy entry commands

IMPLEMENTATION STEPS:
1. Define input parameters (EMA length, RSI length, RSI oversold level)
2. Calculate 50 EMA using ta.ema()
3. Calculate RSI using ta.rsi()
4. Detect crossover with ta.crossover()
5. Combine conditions with logical AND
6. Implement strategy.entry() for positions
7. Add visual markers for entries
8. Include backtest metrics

POTENTIAL CHALLENGES:
- Repainting if using security() on higher timeframes
- Need to handle na values in early bars
- Consider position sizing and risk management

REQUIRED RESOURCES:
- templates/strategies/trend-following/ema-cross.pine
- templates/utilities/risk-management/position-size.pine

示例:需要 UDT 的拆解

用户:“创建一个检测并绘制订单块的指标”

回复:

CONCEPT SUMMARY:
Order block detection with visual zones

UDT ARCHITECTURE:
Type: OrderBlock
Fields:
  - int formationTime        // When OB formed (for xloc.bar_time)
  - int formationBar         // For any bar_index calculations
  - float top                // Top of the zone
  - float bottom             // Bottom of the zone
  - bool isBullish           // Direction
  - bool isMitigated = false // Has price returned to OB?
  - box zone = na            // Visual box

Storage:
  - var array<OrderBlock> orderBlocks = array.new<OrderBlock>()

Methods:
  - delete() - remove box
  - draw() - create box with xloc.bar_time (unlimited lookback!)
  - checkMitigation() - update isMitigated flag

COMPONENTS NEEDED:
1. Impulse move detection (large candle)
2. Prior consolidation zone identification
3. Order block zone calculation
4. Mitigation tracking
5. Visual box rendering

IMPLEMENTATION STEPS:
1. Define OrderBlock UDT with all fields
2. Add delete(), draw(), checkMitigation() methods
3. Detect impulse moves (configurable threshold)
4. Identify consolidation zones before impulse
5. Create OrderBlock UDT when detected
6. Use for...in to iterate and draw all blocks
7. Check mitigation on each bar
8. Add alerts for new OB and mitigation

POTENTIAL CHALLENGES:
- Definition of "impulse move" varies by trader
- May need to limit number of active order blocks
- Historical drawing requires xloc.bar_time (already planned)

REQUIRED RESOURCES:
- templates/indicators/price-action/zones.pine

示例:YouTube 视频流程

用户:“https://youtube.com/watch?v=ABC123”

操作:

python tools/video-analyzer.py "https://youtube.com/watch?v=ABC123"

输出:显示检测到的组件的格式化分析摘要

后续跟进:“这是否正确体现了该策略?在我们实现之前,请告知我是否需要调整任何内容。”

角色边界

此技能用于规划和可视化,而非代码实现。

  • 此技能:分析、规划、拆解并提取概念
  • pine-developer:编写实际的 Pine Script 代码
  • pine-manager:统筹复杂的多步骤实现

评论

支持 Markdown