What is Pine Script?
Pine Script是一种轻量级但功能强大的编程语言,运行在TradingView的云服务器上。您无需安装任何软件,只需在浏览器中编写代码即可创建自定义指标和策略。Pine Script语法简洁直观,特别适合金融分析和交易策略开发。
示例代码:简单的移动平均线交叉策略
//@version=5
strategy("MA Cross Strategy", overlay=true)
fast = input.int(9, "Fast MA")
slow = input.int(21, "Slow MA")
fastMA = ta.sma(close, fast)
slowMA = ta.sma(close, slow)
plot(fastMA, "Fast MA", color.blue)
plot(slowMA, "Slow MA", color.red)
if ta.crossover(fastMA, slowMA)
strategy.entry("Buy", strategy.long)
if ta.crossunder(fastMA, slowMA)
strategy.close("Buy")
Pine Script 核心功能
Built-in Editor
集成在TradingView图表中的代码编辑器,支持语法高亮、自动补全和实时预览。编写代码后点击"添加到图表"即可看到效果。
Strategy Backtesting
内置策略回测引擎,基于历史数据测试您的交易策略。查看收益率曲线、最大回撤、胜率等关键绩效指标。
Community Library
访问社区中数千个公开分享的Pine Script指标和策略。学习他人的代码,在此基础上进行改进和创新。
Real-time Execution
指标和策略在实时市场数据上运行,信号即时触发。配合图表警报功能,不错过任何交易机会。