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

Pine Script问题:EMA10连续2次收盘价低于后平仓逻辑修正

Pine Script 平仓逻辑修正:连续2次收盘价低于EMA10即平仓

你的核心需求是当连续2根K线收盘价均低于EMA10时平仓,无论这两根K线本身是涨是跌,但原代码的twoLowerCloses逻辑错误地判断了连续3根K线收盘价下跌,完全偏离了需求。

修正后的代码片段

ema = ta.ema(close, 10)

// 买卖条件
var float buyPrice = 0
buyCondition = close > ema and strategy.position_size == 0 and f_dateFilter

// 修正后的连续2次收盘价低于EMA10的判断
twoClosesBelowEma = close < ema and close[1] < ema

sellCondition = twoClosesBelowEma and strategy.position_size > 0

关键说明

  • 去掉了原代码中判断K线收盘价连续下跌的逻辑,直接判断当前K线和前一根K线的收盘价都低于EMA10,完全匹配你“连续2次收盘价低于EMA10”的需求。
  • 平仓条件仅需满足上述EMA判断+持有多单(strategy.position_size > 0)即可,无需额外的K线涨跌判断。

内容的提问来源于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 14:54:19