亏损后的 Pinescript 交易延迟
Pinescript trade delay after loss
我正试图在发生亏损交易后延迟交易,但到目前为止没有成功。我的逻辑告诉我这应该有效:
waitafterloss = input(1,'No. of bars to wait after loss')
newloss = (strategy.losstrades > strategy.losstrades[1]) and (strategy.wintrades == strategy.wintrades[1]) and (strategy.eventrades == strategy.eventrades[1])
barssince = ta.barssince(newloss)
waitcondition = barssince >= waitafterloss
但事实并非如此。
我需要 return true 或 false 的“等待条件”,以便我可以在 order/entry 执行中使用它。
有什么想法吗?我究竟做错了什么?也许也有可能有两个输入——延迟和连续亏损交易?谢谢
waitcondition returns true/false,但是我会恢复比较逻辑以匹配目的和变量名称。如果满足条件,下面的脚本将暂停新的长条目:
//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)
waitafterloss = input(100,'No. of bars to wait after loss')
newloss = (strategy.losstrades > strategy.losstrades[1]) and (strategy.wintrades == strategy.wintrades[1]) and (strategy.eventrades == strategy.eventrades[1])
barssince = ta.barssince(newloss)
waitcondition = barssince < waitafterloss
// bgcolor(waitcondition ? color.red : na) // <- uncomment to see the 'pause' on a chart.
longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition) and not waitcondition
strategy.entry("long", strategy.long)
closeCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (closeCondition)
strategy.close("long")
我正试图在发生亏损交易后延迟交易,但到目前为止没有成功。我的逻辑告诉我这应该有效:
waitafterloss = input(1,'No. of bars to wait after loss')
newloss = (strategy.losstrades > strategy.losstrades[1]) and (strategy.wintrades == strategy.wintrades[1]) and (strategy.eventrades == strategy.eventrades[1])
barssince = ta.barssince(newloss)
waitcondition = barssince >= waitafterloss
但事实并非如此。
我需要 return true 或 false 的“等待条件”,以便我可以在 order/entry 执行中使用它。
有什么想法吗?我究竟做错了什么?也许也有可能有两个输入——延迟和连续亏损交易?谢谢
waitcondition returns true/false,但是我会恢复比较逻辑以匹配目的和变量名称。如果满足条件,下面的脚本将暂停新的长条目:
//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)
waitafterloss = input(100,'No. of bars to wait after loss')
newloss = (strategy.losstrades > strategy.losstrades[1]) and (strategy.wintrades == strategy.wintrades[1]) and (strategy.eventrades == strategy.eventrades[1])
barssince = ta.barssince(newloss)
waitcondition = barssince < waitafterloss
// bgcolor(waitcondition ? color.red : na) // <- uncomment to see the 'pause' on a chart.
longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition) and not waitcondition
strategy.entry("long", strategy.long)
closeCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (closeCondition)
strategy.close("long")