损失后的Pinsiprcript贸易延迟

发布于 2025-01-23 09:22:25 字数 483 浏览 1 评论 0原文

我试图在发生损失交易后延迟交易,但到目前为止还没有成功。我的逻辑告诉我,这应该有效:

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

但是没有。

我需要“侍应条”才能返回true或false,以便可以在订单/输入执行中使用它。

有什么想法吗?我在做什么错?也许也有可能有两个输入 - 延迟和失去交易连胜?谢谢

I'm trying to delay trades after a losing trade has happened, but with no success so far. My logic tells me this should work:

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

But it doesnt.

I need the "waitcondition" to return true or false so I could use it in my order/entry execution.

Any ideas? What am I doing wrong? Maybe it would also be possible to have two inputs - delay and losing trades streak? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染火枫林 2025-01-30 09:22:25

waitCondition返回True/fals,但是我会恢复比较逻辑以匹配目的和可变名称。下面的脚本将暂停新的长条目,以防该条件满足条件:

//@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") 

waitcondition returns true/false, however I would revert the comparison logic to match the purpose and variable name. The script below will pause new long entries in case the condition is met:

//@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") 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文