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

TradingView PineScript信号三角替换为K线下水平射线实现咨询

PineScript 射线标记修改实现方案

本次修改核心逻辑为移除原有三角标记代码,新增射线绘制逻辑:上涨信号触发时在对应K线实体底部绘制向右延伸的绿色水平射线,下跌信号触发时在对应K线实体顶部绘制向右延伸的红色水平射线,信号位置和原有三角标记完全对齐。

完整修改后代码

//@version=4
study("attempt 1 - 射线版本", overlay=true)

// 原有K线数据计算逻辑保持不变
BarLow = low
BarHigh = high
BarOpen = open
BarClose = close
PreviousBarHigh = high[2]
PreviousBarLow = low[2]
PreviousBarOpen = open[2]
PreviousBarClose = close[2]

Drop = (BarHigh < PreviousBarOpen) and (BarOpen < PreviousBarOpen) and (BarClose < PreviousBarClose) and (PreviousBarLow > BarHigh)
Increase = (PreviousBarHigh < BarOpen) and (PreviousBarClose < BarOpen) and (PreviousBarHigh < BarLow)

// 上涨信号绿色射线绘制
if Increase
    line.new(
        x1=bar_index - 2, 
        y1=min(open[2], close[2]), 
        x2=bar_index + 10000, // 超大值实现向右无限延伸效果
        y2=min(open[2], close[2]),
        color=color.green,
        width=1,
        style=line.style_solid
    )

// 下跌信号红色射线绘制
if Drop
    line.new(
        x1=bar_index - 2, 
        y1=max(open[2], close[2]), 
        x2=bar_index + 10000,
        y2=max(open[2], close[2]),
        color=color.red,
        width=1,
        style=line.style_solid
    )

// 原有三角标记代码已注释,可按需恢复
// plotshape(Increase, style = shape.triangleup, location = location.belowbar, color = color.green, size = size.tiny, offset=-2)
// plotshape(Drop, style = shape.triangledown , location = location.abovebar, color = color.red, size = size.tiny, offset=-2)

可自定义调整参数

  • 修改width数值可调整射线粗细,数值越大线越粗
  • 修改style参数可切换线型,可选值有line.style_dashed(虚线)、line.style_dotted(点线)
  • 替换color参数值可修改射线颜色

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.19 17:45:03