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

如何仅在至少5根前K线未触碰EMA时标记K线?

修改后的Pine Script代码
//@version=5
indicator("My script", overlay=true)

ema_val = ta.ema(close, 9)
// 判断当前K线是否触碰EMA
ema_touch_current = (ema_val <= high) and (ema_val >= low)
// 检查过去5根K线是否均未触碰EMA
no_touch_in_last_5 = ta.sum(ema_touch_current[1], 5) == 0
// 最终标记条件:当前触碰EMA + 过去5根都没触碰
mark_condition = ema_touch_current and no_touch_in_last_5

plot(ema_val)
plotshape(mark_condition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)

关键逻辑说明

  • ema_touch_current:保留原逻辑,判断当前K线的高低价区间是否覆盖EMA值,确认当前K线触碰EMA
  • no_touch_in_last_5:用ta.sum(ema_touch_current[1], 5)统计前1至前5根K线的触碰次数,结果为0则代表这5根K线均未触碰EMA
  • mark_condition:将两个条件结合,仅当同时满足时才显示标记

内容的提问来源于stack exchange,提问作者Kai Jun Seah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 16:38:09