Pine Script交易条件下的多个出口



我创建了一个指示器这只适用于长期,并显示了我的头寸的进入和退出(获利)。但在战略制定过程中,基于指标我遇到了几个问题:

1。当我尝试设置两个不同的出口时对于策略-止损和获利,只有一个出口有效(当退出交易的条件为真时触发获利了结,当多个指标给出退出信号时条件变为真)

2。如果我尝试设置止损,它大部分时间工作不正确-我想通过止损退出当前蜡烛的低价交易,但止损触发时,止损价格条件(ta.lowest(low,20))为真,为未来的蜡烛,而不是坚持我进入交易的那个

期望止损点以绿色标示,不希望止损点以红色标示

下面是我的策略的示例代码:

// 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 = [enter image description here](https://i.stack.imgur.com/c2XjW.png)
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)结合起来,但仍然不起作用,因为我的止损不会触发

您需要像这样使用一个strategy.exit调用

// 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 = [enter image description here](https://i.stack.imgur.com/c2XjW.png)
strategy.entry("ENTER", strategy.long,qty,limit = high,stop = stopPrice)
strategy.exit(id = "STOP LOSS" ,from_entry = "ENTER",stop = stopPrice,limit = buyConditionEscape and inTradeWindow ? low : na)

最新更新