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

求助:Candle Wick/Shadow未触发平仓限制,如何实现影线越价平仓?

影线穿越目标价格时平仓的实现方案

核心逻辑是检测蜡烛的影线顶端/底端是否触及或穿越目标价格,再触发平仓指令。下面以TradingView的Pine Script为例,给出具体实现:

关键步骤

  • 定义你的目标价格(对应图中的绿色区间带)
  • 针对持仓方向,判断影线是否突破目标价
  • 满足条件时执行平仓

代码示例

//@version=5
strategy("影线触发平仓策略", overlay=true, default_qty_type=strategy.cash, default_qty_value=10000)

// 替换为你的实际目标价格(示例用布林带上轨)
targetPrice = ta.bb(close, 20, 2).upper

// 多单入场逻辑(可根据你的策略修改)
if ta.crossover(ta.sma(close, 5), ta.sma(close, 20))
    strategy.entry("多单", strategy.long)

// 多单平仓:上影线突破目标价格时平仓
if strategy.position_size > 0 and high >= targetPrice
    strategy.close("多单")

// 空单入场逻辑(可根据你的策略修改)
if ta.crossunder(ta.sma(close, 5), ta.sma(close, 20))
    strategy.entry("空单", strategy.short)

// 空单平仓:下影线跌破目标价格时平仓
if strategy.position_size < 0 and low <= targetPrice
    strategy.close("空单")

// 绘制目标价格线
plot(targetPrice, color=color.green, title="目标价格")

补充说明

  1. 若要避免假突破,可加入收盘确认条件,比如多单平仓改成:strategy.position_size > 0 and high >= targetPrice and close < targetPrice(即影线突破后,蜡烛收盘回落到目标价下方)
  2. 其他交易平台(如MT4/MT5)逻辑一致:获取K线的high/low值与目标价对比,调用平台自带的平仓函数即可
  3. targetPrice可替换为你实际使用的区间带、支撑阻力线等指标

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 20:30:53