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

Pine Script策略多退出条件异常:止损与止盈故障排查

策略开发问题求助

我开发了一款仅适用于多头的指标,可显示仓位的入场和止盈信号,但基于该指标开发策略时遇到两个问题:

  • 设置止损(stop-loss)和止盈(take-profit)两个退出条件时,仅其中一个生效(止盈在多指标给出退出信号时触发);
  • 止损设置多数情况下异常:我希望以入场K线的低点作为止损价,但当前止损在后续K线满足ta.lowest(low,20)条件时才触发,而非绑定入场K线。
    (注:预期止损点为绿色标记,非预期为红色标记)

以下是策略示例代码:

// Long enter conditions
emaConditionE = false  
macdConditionE = false    
rsiConditionE = false   
buyConditionE = false   

buyConditionEnter := emaConditionE and 
     macdConditionE and 
     rsiConditionE and 

stopPrice = ta.lowest(low,20)

// Long escape conditions
buyConditionEscape := macdConditionEs and rsiConditionEs 

// Strategy Orders
if (buyConditionEnter and inTradeWindow) 
    qty = // 此处原代码为输入数量的内容,暂留空
    strategy.entry("ENTER", strategy.long,qty,limit = high,stop = stopPrice)
if(buyConditionEscape and inTradeWindow)
    strategy.exit(id = "TAKE" ,from_entry = "ENTER",limit = low)


strategy.exit(id = "STOP LOSS" ,from_entry = "ENTER",stop = stopPrice)

我曾尝试将止损与入场指令合并为strategy.order("ENTER", strategy.long,qty,limit = high,stop = stopPrice),但止损仍无法触发。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 04:05:15