返回顶部
p

pine-patterns松树模式

Pine Script v5/v6 indicator scaffold and patterns. Provides structure guidance and triggers doc-researcher for current syntax verification. Use when developing TradingView indicators.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
299
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

pine-patterns

Pine Script 模式

用于 Pine Script v5/v6 指标开发的轻量级脚手架。

生成代码前

务必使用文档研究员代理或 Ref MCP 工具验证:

  • - 当前函数签名
  • v5 与 v6 语法差异
  • 已弃用的函数

文件约定

  • - 版本头://@version=6(优先使用 v6)
  • 许可证:Mozilla Public License 2.0
  • 文件命名:LB_*.pine
  • 作者:Luther Barnum

输入组结构

标准组(使用 group= 参数):

功能开关 - 主启用/禁用开关
VWAP 设置 - VWAP 配置
VWAP 带 - 标准差带设置
时段设置 - 基于时间的参数
初始平衡 - IB 配置
开盘区间 - OR 设置
枢轴点 - 枢轴配置
显示选项 - 视觉设置
颜色 - 颜色配置

时段默认值

  • - RTH:美国东部时间上午 9:30 - 下午 4:00
  • 时区:America/New_York
  • 检测:time(timeframe.period, sessionString)

资源限制

适当设置:

  • - maxbarsback - 历史数据访问
  • maxlabelscount - 标签对象(默认 500)
  • maxlinescount - 线条对象(默认 500)

完整示例

参考:/Users/lgbarn/Personal/Indicators/Tradingview/LBRHMAs.pine

pinescript
//@version=6
// 此 Pine Script® 代码受 Mozilla Public License 2.0 条款约束,详见 https://mozilla.org/MPL/2.0/
// © lgbarn

indicator(LB 简单均线交叉, shorttitle=LB_MACross, overlay=true)

// === 输入 ===
fastLength = input.int(9, 快线均线长度, minval=1, group=均线设置)
slowLength = input.int(21, 慢线均线长度, minval=1, group=均线设置)
useLightTheme = input.bool(false, 浅色主题, group=显示)

// === 计算 ===
fastMA = ta.ema(close, fastLength)
slowMA = ta.sma(close, slowLength)

// === 颜色 ===
fastColor = useLightTheme ? color.new(#0000FF, 0) : color.new(#00FFFF, 0)
slowColor = useLightTheme ? color.new(#FF0000, 0) : color.new(#FF6600, 0)

// === 绘图 ===
plot(fastMA, title=快线均线, color=fastColor, linewidth=2)
plot(slowMA, title=慢线均线, color=slowColor, linewidth=2)

关键模式

持久状态(时段重置)

pinescript var float cumulativeValue = 0.0 var float sessionHigh = na var float sessionLow = na

if ta.change(time(D)) != 0
cumulativeValue := 0.0
sessionHigh := high
sessionLow := low

时段检测

pinescript // 检查是否在 RTH 时段内 isSessionTime = time(timeframe.period, 0930-1600:23456)

// 检测新时段开始
isNewSession = ta.change(time(D)) != 0

// 带时区的时段
isRTH = not na(time(timeframe.period, 0930-1600, America/New_York))

主题颜色

pinescript useLightTheme = input.bool(false, 浅色主题, group=显示) lineColor = useLightTheme ? color.new(#000000, 0) : color.lime fillColor = useLightTheme ? color.new(#000000, 90) : color.new(color.lime, 90)

VWAP 计算模式

pinescript var float cumVolume = 0.0 var float cumVwap = 0.0 var float cumVwap2 = 0.0

if isNewSession
cumVolume := 0.0
cumVwap := 0.0
cumVwap2 := 0.0

cumVolume += volume
cumVwap += volume * hlc3
cumVwap2 += volume hlc3 hlc3

vwapValue = cumVolume > 0 ? cumVwap / cumVolume : na
variance = cumVolume > 0 ? cumVwap2 / cumVolume - vwapValue * vwapValue : na
stdev = variance > 0 ? math.sqrt(variance) : na

upperBand = vwapValue + stdev
lowerBand = vwapValue - stdev

均线模式

pinescript // 简单移动平均线 smaValue = ta.sma(close, length)

// 指数移动平均线
emaValue = ta.ema(close, length)

// 加权移动平均线
wmaValue = ta.wma(close, length)

// 赫尔移动平均线
hmaValue = ta.hma(close, length)

错误处理模式

检查 NA 值

pinescript // 使用 nz() 将 NA 替换为默认值 safeValue = nz(calculatedValue, 0.0)

// 使用前检查值是否有效
if not na(vwapValue)
plot(vwapValue, color=color.blue)

验证输入

pinescript // 确保慢线 > 快线 validatedSlow = math.max(slowLength, fastLength + 1)

处理除零

pinescript divisor = high - low result = divisor != 0 ? (close - low) / divisor : 0.5

检查 K 线历史

pinescript // 确保有足够的 K 线进行计算 if bar_index >= length - 1 // 可以安全计算 value = ta.sma(close, length)

运行时错误(v6)

pinescript if period < 1 runtime.error(周期必须 >= 1)

交易背景

  • - 关注品种:/ES、/NQ 期货
  • 时间周期:5 分钟
  • 关键概念:VWAP+1SD、TWAP、IB、经典枢轴
  • 方法:机构模式优先于零售模式

外部库

可用导入:

  • - import jmosullivan/SessionVolumeProfile/12 as SVP
  • import jmosullivan/Session/5 as Session

文档来源

使用 Ref MCP 搜索:

  • - TradingView Pine Script 参考
  • Pine Script 用户手册

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 pine-patterns-1776201133 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 pine-patterns-1776201133 技能

通过命令行安装

skillhub install pine-patterns-1776201133

下载

⬇ 下载 pine-patterns v1.0.0(免费)

文件大小: 3.08 KB | 发布时间: 2026-4-15 10:34

v1.0.0 最新 2026-4-15 10:34
- Initial release of pine-patterns.
- Provides a lightweight scaffold for Pine Script v5/v6 indicator development.
- Includes conventions for file structure, session defaults, and resource limits.
- Offers reusable code patterns for state management, session detection, moving averages, VWAP, and error handling.
- Documents group input standards, theming, and typical institutional trading features.
- Recommends verification with doc-researcher for current Pine Script syntax and deprecation status.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部