绘图
使用绘图函数、形状、填充和颜色可视化指标数据
绘图函数
| 函数 | 说明 |
|---|---|
plot(series, title?, options?) | 绘制线、面积、直方图或其他系列样式 |
plotshape(series, title?, options?) | 绘制形状标记(箭头、圆点、菱形等) |
plotchar(series, title?, char?, options?) | 绘制字符标记 |
plotarrow(series, title?, options?) | 绘制箭头标记 |
plotbar(open, high, low, close, title?, options?) | 绘制OHLC柱 |
plotcandle(open, high, low, close, title?, options?) | 绘制K线图 |
hline(price, title?, color?, linestyle?, linewidth?, editable?, display?) | 在固定价格水平绘制水平线 |
fill(plot1, plot2, color?) | 填充两个绘图之间的区域 |
bgcolor(color, offset?, options?) | Studio 不渲染此输出,并会报告不支持的样式警告 |
barcolor(color, offset?, options?) | Studio 不渲染此输出;请改用绘图的 color 选项 |
绘图样式
使用 plot.style_* 常量控制数据的渲染方式:
| 样式 | 说明 |
|---|---|
plot.style_line | 连续线(默认) |
plot.style_linebr | 在 na 值处断开的线 |
plot.style_stepline | 阶梯线 |
plot.style_stepline_diamond | 带菱形标记的阶梯线 |
plot.style_steplinebr | 带断点的阶梯线 |
plot.style_area | 线下方填充区域 |
plot.style_areabr | 在 na 处断开的区域 |
plot.style_histogram | 垂直直方图柱 |
plot.style_columns | 柱状图 |
plot.style_circles | 圆形标记 |
plot.style_cross | 十字标记 |
线条样式(用于 plot 和 hline)
PineTS 接受这些常量,但 Studio 目前渲染绘图时不会保留 linestyle。虚线和点线样式会显示为实线。
| 样式 | 说明 |
|---|---|
plot.linestyle_solid | 实线 |
plot.linestyle_dashed | 虚线 |
plot.linestyle_dotted | 点线 |
hline.style_solid | 水平实线 |
hline.style_dashed | 水平虚线 |
hline.style_dotted | 水平点线 |
示例
基础折线图
indicator('EMA Crossover', { overlay: true });
const fast = ta.ema(close, 9);
const slow = ta.ema(close, 21);
plot(fast, 'Fast EMA', { color: '#2962FF' });
plot(slow, 'Slow EMA', { color: '#FF6D00' });直方图
indicator('MACD Histogram');
const [macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9);
plot(hist, 'Histogram', {
style: plot.style_histogram,
color: hist > 0 ? '#26A69A' : '#EF5350'
});
plot(macdLine, 'MACD', { color: '#2962FF' });
plot(signalLine, 'Signal', { color: '#FF6D00' });图形间填充
indicator('Bollinger Bands', { overlay: true });
const [mid, upper, lower] = ta.bb(close, 20, 2);
const p1 = plot(upper, 'Upper', { color: '#F23645' });
plot(mid, 'Middle', { color: '#787B86' });
const p2 = plot(lower, 'Lower', { color: '#089981' });
fill(p1, p2);形状标记
// Plot buy/sell arrows at crossover points
if (ta.crossover(fast, slow)) {
plotshape(close, 'Buy', {
style: shape.triangleup,
location: location.belowbar,
color: '#00FF00',
size: size.small
});
}
if (ta.crossunder(fast, slow)) {
plotshape(close, 'Sell', {
style: shape.triangledown,
location: location.abovebar,
color: '#FF0000',
size: size.small
});
}形状常量
| 常量 | 说明 |
|---|---|
shape.triangleup | 向上三角形 |
shape.triangledown | 向下三角形 |
shape.circle | 圆形 |
shape.cross | 十字 |
shape.xcross | X 形交叉 |
shape.diamond | 菱形 |
shape.square | 方形 |
shape.arrowup | 向上箭头 |
shape.arrowdown | 向下箭头 |
shape.flag | 旗形 |
shape.labelup | 向上标签 |
shape.labeldown | 向下标签 |
位置常量
| 常量 | 说明 |
|---|---|
location.abovebar | 柱上方 |
location.belowbar | 柱下方 |
location.top | 窗格顶部 |
location.bottom | 窗格底部 |
location.absolute | 精确值处 |
尺寸常量
| 常量 | 说明 |
|---|---|
size.tiny | 极小 |
size.small | 小 |
size.normal | 正常 |
size.large | 大 |
size.huge | 极大 |
size.auto | 自动 |
背景色与柱颜色
Studio 不渲染 bgcolor() 或 barcolor() 的输出,这些调用会产生不支持的样式警告。要可视化某个条件,请改用受支持的 plot() 或 plotshape() 的 color 选项。
颜色可以使用十六进制字符串指定(例如 '#FF0000'),也可以使用 color 命名空间(例如 color.red)。添加两位十六进制数字表示 alpha 透明度(例如 '#FF000080' 表示 50% 不透明度)。