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

请求将带止损单的Pine Script策略转换为指标(Study)

将Volty Expan Close策略转换为Pine Script指标

原策略通过止损单(stop单)触发多空入场,转换为指标时需将触发条件可视化,具体实现如下:

//@version=5
indicator("Volty Expan Close Indicator", overlay=true)
length = input(5)
numATRs = input(0.75)
atrs = ta.sma(ta.tr, length)*numATRs

// 计算多空触发水平
long_trigger_level = close + atrs
short_trigger_level = close - atrs

// 判断触发条件:下一根K线突破触发水平视为信号
long_signal = ta.close[1] > long_trigger_level[1]
short_signal = ta.close[1] < short_trigger_level[1]

// 画出触发水平(可选,方便观察)
plot(long_trigger_level, color=color.green, title="Long Trigger Level", style=plot.style_circles)
plot(short_trigger_level, color=color.red, title="Short Trigger Level", style=plot.style_circles)

// 标记信号点
plotshape(long_signal, title="Long Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="L")
plotshape(short_signal, title="Short Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="S")

关键转换说明:

  • 把strategy()替换为indicator(),这是Pine Script v5中创建指标的基础函数
  • 原策略的strategy.entry是下单逻辑,指标无法执行下单,因此通过判断价格是否突破触发水平来生成信号
  • 用close[1]对比前一根K线的触发水平,模拟原策略中价格触及stop单时的入场逻辑
  • 额外添加触发水平绘制和信号标记,让策略逻辑直观可见

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 00:47:38