pine-script - 可以同时运行 2 个长订单吗?
问题描述
在 tradingview Pine Script 中,我发现如果我在一个策略中有两个多头订单,它会在第一个策略结束后执行第二个 strategy.entry 多头订单。是否有可能在第一个多头订单仍处于打开状态时运行第二个多头订单?如何?
编辑: 我尝试过金字塔,但如果条件仍然适用,它会在第二天执行相同的订单,这是我不想要的。
比如说,有两个 strategy.entry 订单“Buy1”和“Buy2”。我想要的是这样的:
- 无论“Buy1”是打开还是关闭,都能执行“Buy2”。
- 无论“Buy2”是打开还是关闭,都能执行“Buy1”。
- 当现有“Buy1”未平仓时,不得重复“Buy1”。
- 当现有“Buy2”未平仓时,不得重复“Buy2”。
我如何实现上述目标。下面是一个示例代码。
//@version=4
strategy(title="Double buy Test", overlay=true, pyramiding=1, close_entries_rule = "ANY")
rsi14 = rsi(close, 14)
sma100 = sma(close, 100)
sma50 = sma(close, 50)
bought = strategy.position_size[0] > strategy.position_size[1]
since_entry = barssince(bought)
firstorder = close > sma100
secondorder = close > sma50
firstexit = rsi14 < 30
secondexit = rsi14 > 70
strategy.entry(id = "BUY1", long = true, when = firstorder )
strategy.entry(id = "BUY2", long = true, when = secondorder)
strategy.close(id = "BUY1", when = firstexit)
strategy.close(id = "BUY2", when = secondexit)
解决方案
推荐阅读
- shell - iptables 规则是否正确?
- amazon-web-services - cloudformation 部署的 UI5 Web 应用,如何创建 SSM 参数以便以后可以访问?
- rust - 在使用 lto=true 构建 Rust 二进制文件时,有没有办法限制链接器检查的 crate?
- python - 在 Python 中一对一比较两个列表
- css - Bootstrap DateTimePicker:数字列之间的空间
- python - 模拟类函数应该被调用一次,但 call_count == 0?
- php - 调用字符串上的成员函数(但函数返回字符串)PHP
- sql - 如果最新记录状态匹配,则更新所有其他记录
- c# - 使用 RabbitMq 的 MassTransit 在发生错误时未重试
- javascript - JS 在查找参数值时是否遵循动态范围链