pine-script - 带有错误 ID 的 Pine 脚本和交易视图关闭条目
问题描述
我是第一次测试 pine 编辑器和策略测试器,但我试图理解和意外的行为。
下面是我正在测试的一个简单策略的代码。(基本上我想了解 strategy.close 和 strategy.exit 之间的区别)所以为了做到这一点,我只需在周一买入并在周五平仓。为了真正测试平仓,我在周三输入了一个新仓位,我希望代码永远不会关闭周三的仓位。但是,如果我检查“策略测试器”的“交易列表”,我可以看到在交易编号 2 中,周三头寸被周一平仓订单平仓。(见附图)。
有人可以澄清为什么会这样吗?我还注意到星期一的买入信号发生在星期二,即使我激活了 process_orders_on_close(否则它会在星期三发生),并且在所有工作日都是如此。
谢谢你的帮助。干杯。
//@version=4
strategy("My Strategy", overlay=true, process_orders_on_close=true, pyramiding=2)
testStartYear = input(2021, "Backtest Start Year")
testStartMonth = input(06, "Backtest Start Month")
testStartDay = input(06, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)
// Stop us from entering two wednesday positions when pyramiding is on
// This would prevent us entering a monday position.
wedEntered = bool(na)
wedEntered := nz(wedEntered[1], false)
monCondition = time >= testPeriodStart and dayofweek == dayofweek.monday
wedCondition = time >= testPeriodStart and dayofweek == dayofweek.wednesday and (not wedEntered[1])
if (monCondition)
strategy.entry("Monday", strategy.long)
// strategy.exit("Monday TP", "Monday", limit=high)
if (wedCondition)
wedEntered := true
strategy.entry("Wednesday", strategy.long)
strategy.close("Monday", when=dayofweek == dayofweek.friday)
// strategy.close_all(when=dayofweek == dayofweek.friday)
解决方案
您需要像这样指定close_entries_rule
参数:
strategy("My Strategy", overlay=true, process_orders_on_close=true, pyramiding=2, close_entries_rule="ANY")
推荐阅读
- javascript - 如何从 html 获取文本字段值并将其传递给 REST GET 服务并在动态 HTML 表中显示响应
- dialogflow-es - 处理 if-else 条件的方法是对话流?
- javascript - 如何使用 SQLAlchemy 全栈开发 udacity 课程将子元素与父元素关联
- sql-server - 带有 SQL Server IGNORE_DUP_KEY 的实体框架
- .net - 通过 Visual Studio 中的自动接受 Nuget 停止许可证接受弹出窗口
- css - JavaFX SetText CSS 选项
- xml - 通过 PL/SQL 将 CLOB XML 发布到 URL
- java - 寻找基于终端的 IDE 以通过 SSH 工作 - Java
- reactjs - 材质 UI 调色板未更新
- c# - Xamarin.Forms 将 IsEnable 设置为 true 不起作用