Possible to run 2 long orders simultaneously?

Viewed 782

In tradingview Pine Script, I find that if I have two long orders in a strategy, it executes the 2nd strategy.entry long order only after the first one ends. Is it possible to have the 2nd long order run while the 1st long order is still open? How?

Edit: I have tried pyramiding, but it executes the same order next day if the condition still applies, which I do not want.

Say, there are two strategy.entry orders "Buy1" and "Buy2". What I want is this:

  1. Able to execute "Buy2" irrespective of whether "Buy1" is open or closed.
  2. Able to execute "Buy1" irrespective of whether "Buy2" is open or closed.
  3. Must not repeat "Buy1" when there is an existing "Buy1" open.
  4. Must not repeat "Buy2" when there is an existing "Buy2" open.

How do I achieve the above. Below is a sample code.

//@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)
0 Answers
Related