pinescript

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Pine Script

Pine Script

Overview

概述

Provide Pine Script v6 guidance for indicators, strategies, and libraries. Apply non-repainting and performance best practices. Support generating Pine Script via other languages (TypeScript, Python, etc.) by keeping generated output compliant with v6 guidance. Run linting with the bundled script wrapper around
pinescript-lint
.
提供关于指标、策略和库的Pine Script v6指导。应用无重绘与性能优化最佳实践。支持通过其他语言(TypeScript、Python等)生成Pine Script,确保生成的输出符合v6规范。通过基于
pinescript-lint
封装的脚本运行代码检查。

Workflow

工作流程

  1. Determine script type and version
    • Add
      //@version=6
      and choose
      indicator()
      ,
      strategy()
      , or
      library()
      .
  2. Apply execution model and repainting safeguards
    • Use
      barstate.isconfirmed
      , historical offsets, and
      request.security()
      lookahead guidance.
  3. Optimize performance and state
    • Prefer
      var
      /
      varip
      for state, limit loops, precompute constants, avoid redundant security calls.
  4. Generate Pine Script from other languages when needed
    • Emit Pine Script v6-compliant output and validate by inspection or TradingView editor diagnostics.
  5. Lint before delivery (manual Pine Script only)
    • Run
      node scripts/pinescript_lint.mjs <path>
      to check formatting and basic issues.
  1. 确定脚本类型与版本
    • 添加
      //@version=6
      ,并选择
      indicator()
      strategy()
      library()
  2. 应用执行模型与防重绘保障
    • 使用
      barstate.isconfirmed
      、历史偏移量,以及
      request.security()
      的前瞻操作指导。
  3. 优化性能与状态管理
    • 优先使用
      var
      /
      varip
      来管理状态,限制循环使用,预计算常量,避免冗余的security调用。
  4. 必要时从其他语言生成Pine Script
    • 生成符合Pine Script v6规范的输出,并通过人工检查或TradingView编辑器诊断工具验证。
  5. 交付前进行代码检查(仅手动编写的Pine Script)
    • 运行
      node scripts/pinescript_lint.mjs <路径>
      来检查格式与基础问题。

References

参考资料

  • Pine Script v6 concepts and best practices:
    references/pinescript_v6.md
  • Linting workflow and linter configuration:
    references/linting.md
  • Pine Script v6概念与最佳实践:
    references/pinescript_v6.md
  • 代码检查工作流与检查器配置:
    references/linting.md

Scripts

脚本

  • Lint Pine Script files:
    scripts/pinescript_lint.mjs
  • Lint script tests:
    scripts/pinescript_lint.test.mjs
  • 检查Pine Script文件:
    scripts/pinescript_lint.mjs
  • 检查脚本测试:
    scripts/pinescript_lint.test.mjs