微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Pinescript (Tradingview) 每次都停止和限制不起作用

如何解决Pinescript (Tradingview) 每次都停止和限制不起作用

longcon = crossover(ema5,ema21)
longCondition1 = longcon[4]
longCondition2 = ema50 > ema200 ? 1: 0
longCondition3 = bbr > 0.75 ? 1: 0
longCondition4 = sig > 15 ? 1: 0
longCondition5 = ao > 2 ? 1: 0
if (longCondition1 and longCondition2 and longCondition3 and longCondition4 and longCondition5)
    strategy.entry("long",strategy.long)
    strategy.exit("exit","long",stop=strategy.position_avg_price*0.98,limit=strategy.position_avg_price*1.01)
plot(strategy.position_avg_price)
plot(strategy.position_avg_price*0.98)
plot(strategy.position_avg_price*1.01)

我一直在尝试回测此策略,但由于某种原因,止损和获利(限价)无法正常工作,我不知道为什么。我绘制了这些值,当达到这些级别时,脚本不会执行。

enter image description here

您可以看到第一次退出错误的,因为价格上涨了 1%,但脚本没有卖出。第二次围绕脚本工作正常。这是什么原因造成的?

解决方法

我刚刚想通了:

if (longCondition1 and longCondition2 and longCondition3 and longCondition4 and longCondition5)
    strategy.entry("long",strategy.long)
strategy.exit("exit","long",stop=strategy.position_avg_price*0.98,limit=strategy.position_avg_price*1.01)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。