首页 > 解决方案 > 可以同时运行 2 个长订单吗?

问题描述

在 tradingview Pine Script 中,我发现如果我在一个策略中有两个多头订单,它会在第一个策略结束后执行第二个 strategy.entry 多头订单。是否有可能在第一个多头订单仍处于打开状态时运行第二个多头订单?如何?

编辑: 我尝试过金字塔,但如果条件仍然适用,它会在第二天执行相同的订单,这是我不想要的。

比如说,有两个 strategy.entry 订单“Buy1”和“Buy2”。我想要的是这样的:

  1. 无论“Buy1”是打开还是关闭,都能执行“Buy2”。
  2. 无论“Buy2”是打开还是关闭,都能执行“Buy1”。
  3. 当现有“Buy1”未平仓时,不得重复“Buy1”。
  4. 当现有“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)

标签: pine-script

解决方案


推荐阅读