You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Pine Script中修改入场与出场的文本及颜色?

在Pine Script中修改入场/出场标记的文本内容与颜色

当然可以,你完全能自定义入场、出场标记的文本内容和颜色,核心通过label.new()或plotshape()函数实现,以下是具体示例和说明:

用label.new()实现自定义标记

//@version=5
indicator("自定义入场出场标记", overlay=true)

// 模拟入场/出场信号(以均线交叉为例)
long_signal = ta.crossover(ta.sma(close, 5), ta.sma(close, 20))
short_signal = ta.crossunder(ta.sma(close, 5), ta.sma(close, 20))

// 入场标记:自定义文本+蓝色背景
if (long_signal)
    label.new(
        bar_index, low, 
        text="做多入场", 
        color=color.blue, 
        textcolor=color.white, 
        style=label.style_label_up,
        size=size.small
    )

// 出场标记:自定义文本+粉色背景
if (short_signal)
    label.new(
        bar_index, high, 
        text="做空出场", 
        color=color.pink, 
        textcolor=color.white, 
        style=label.style_label_down,
        size=size.small
    )

用plotshape()实现自定义标记

如果你习惯用形状类标记,也可以直接修改plotshape()的参数:

//@version=5
indicator("自定义入场出场标记", overlay=true)

long_signal = ta.crossover(ta.sma(close, 5), ta.sma(close, 20))
short_signal = ta.crossunder(ta.sma(close, 5), ta.sma(close, 20))

plotshape(long_signal, title="做多入场", location=location.belowbar, 
          color=color.blue, style=shape.labelup, text="入场", textcolor=color.white)
plotshape(short_signal, title="做空出场", location=location.abovebar, 
          color=color.pink, style=shape.labeldown, text="出场", textcolor=color.white)

关键参数说明

  • text:直接设置想要显示的文本,比如"加仓"、"止盈"等自定义内容
  • color:控制标记背景色,支持内置颜色(color.blue/color.pink)或自定义RGB颜色(color.rgb(0,128,255))
  • textcolor:控制文本颜色,建议选与背景色对比强烈的颜色(如白色)提升可读性
  • style:调整标记样式,比如label.style_arrow_up是箭头标记,shape.labelup是标签式标记

内容的提问来源于stack exchange,提问作者candlestickb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 17:45:49