pine-script - 多头/空头策略仅显示多头平仓挂单
问题描述
这里是新手。我正在制定多头/空头策略。当我运行我的策略时,多头头寸按预期平仓,但我认为空头头寸不是。因为我将每个订单的费用设置为美元,所以我想确保每个市场订单都打开/关闭,以便我可以回溯测试我的策略。我的代码如下。
hist = macd - signal
if (hist > 0.15)
strategy.entry("Long", strategy.long, comment="Long")
if (hist < -0.15)
strategy.close("Long")
if (hist < -0.15)
strategy.entry("Short", strategy.short, comment="Short")
if (hist > 0.15)
strategy.close("Short")
谢谢!
解决方案
这是正确的行为,因为您的条件实际上定义为
hist = macd - signal
if (hist > 0.15)
strategy.entry("Long", strategy.long, comment="Long")
strategy.close("Short")
if (hist < -0.15)
strategy.close("Long")
strategy.entry("Short", strategy.short, comment="Short")
因此,当您在条件下进入空头头寸时(hist < -0.15)
,在下一个柱状图上,当if (hist > 0.15)
为真时,您将恢复Short
头寸strategy.entry("Long", strategy.long, comment="Long")
。
推荐阅读
- android - 从android中获取手机号码以编程方式插入sim
- typescript - TypeScript 条件类型的映射与受约束的泛型不同吗?
- python - 如果下一个按钮不可用,如何进行分页
- intellij-idea - IntelliJ 运行/调试控制台窗口
- flutter - 我从 firestore 检索数据,但是,如何在我的颤振应用程序中围绕输出数据创建边框?
- reactjs - 如何使用纱线正确安装包?
- html - 如何将一个 div 居中在一个容器 div 中,该容器 div 里面有另一个 div 浮动在右侧?
- javascript - 如何呈现从 Firestore 获取的表中的数据?
- java - 适用于 Android 的 SendGrid
- mongodb - MongoDB的最佳索引策略