📘 Pine Script V5 · 进阶篇

第18–23章 · 配色 · 提醒 · 数组 · 调试 · 发布 · 技巧
🎨 第18.1章 颜色表示法 4种
具名常量17种预定义 (如 color.red)
十六进制#FF5252 (RGB) / #FF525280 (RGBA)
color.rgb()十进制 RGB/RGBA
color.new()颜色 + 透明度
aqua black blue fuchsia green orange red yellow …共17种
🖌️ 第18.2章 color 相关函数
color.new加透明度color.new(color.red,50)
color.rgbRGB+透明度color.rgb(255,0,0,50)
color.from_gradient渐变色
input.color界面可调颜色
bgcolor背景配色
fill区域填充 (支持渐变)
barcolorK线配色
bgcolor(close < open ? color.new(color.red,70) : color.new(color.green,70))
📐 第18.3章 Z-index 堆叠顺序
默认从下到上: Background → Plots → Hlines → Fills → Boxes → Labels → Lines → Tables
explicit_plot_zordertrue → 按执行顺序堆叠;false → 自动Z-index
indicator("Gradient Fill", explicit_plot_zorder=true)
🌈 第18.4章 颜色渲染 vs 渐变
颜色渲染条件表达式/语句映射颜色
颜色渐变fillcolor.from_gradient
// 条件渲染 myColor = close > open ? color.green : color.red plot(close, color=myColor) // 渐变 color.from_gradient(signal, -200, 200, bearColor, bullColor)
🔔 第19.1章 提醒类型 4种
交易观点Idea Alerts
绘图类Drawing Alerts
一般类Generic Alerts (界面创建)
脚本类Script Alerts (alert/alertcondition)
alert可用于 indicator / strategy
alertcondition仅用于 indicator
📢 第19章 alert 系列函数
alertcondition静态提醒alertcondition(xUp, "Long")
alert动态提醒alert("RSI is " + str.tostring(r))
freqalert.freq_once_per_bar / alert.freq_once_per_bar_close
strategy.*alert_message 定制提醒信息
alertcondition(bullCond, title="底背离", message="Bullish Divergence")
📊 第20章 数组 (Array) 一维
声明int[] arr = array.new()
读写array.get() / array.set()
插入unshift / insert / push
删除remove / shift / pop / clear
计算avg / max / min / sum / stdev / variance …
操纵concat / copy / sort / reverse / slice
查找includes / indexOf / lastIndexOf
🔹 最大长度 100,000 · 元素为 series 形式
🐞 第21章 调试方法
plot数值变量plot(myVar, color=color.black)
plotchar字符变量plotchar(bar_index, 'idx', '❄')
label.new显示变量值 (最多50个)
数据窗口右侧面板查看变量值
label.new(bar_index, high, text=str.tostring(myVar))
🚀 第22章 发布脚本
隐私Public (公开) / Private (私有)
可见性Open (开源) / Protected / Invite-only
更新Publish Script → Update Existing Script
📌 公开脚本需审核,不可删除
🧩 第23.1章 合并指标技巧
目的节省指标数量 (免费账户限3个)
方法复制脚本,合并代码,修改变量名
// 合并 MA + 布林带 indicator("MAs & BB", overlay=true) // 均线部分 out5 = ta.sma(src5, len5) // 布林带部分 basis = ta.sma(src, length)
📌 第23.2章 K线形态识别
Doji十字星
Evening Star黄昏之星
Morning Star早晨之星
Shooting Star射击之星
Hammer锤子线
Engulfing吞没线
plotshape(data, style=shape.arrowdown, text="Evening\nStar")
⚙️ 第23.3章 定制指标实例
RSI增强超买/超卖背景色红绿柱
ARBR人气情绪指标 (自建)
// RSI 超买超卖背景 bgcolor(rsi <= lowLine ? color.new(color.green,70) : rsi >= upLine ? color.new(color.red,70) : na)
🔄 第23.4章 indicator ↔ strategy
indicator→strategy修改函数名,加入 strategy.entry/exit
strategy→indicator移除开平仓,保留绘图
// 转换前 (indicator) plotshape(longCondition, text="buy") // 转换后 (strategy) if longCondition strategy.entry("Long", strategy.long)
📌 进阶关键提醒
颜色避免使用纯黑/白,适应亮/暗背景
渐变级数控制在10级以内
提醒脚本类提醒仍需在界面创建
数组一维,最大100k,元素为series
调试label.new 最多显示50个值
发布公开脚本不可删除,需审核
整理自《零基础学Pine Script》第18-23章 · 进阶篇 · 配色 / 提醒 / 数组 / 调试 / 发布 / 实战技巧