I tried pyramiding. It does not do what I want. Let me explain
Consider there are 2 different strategy.entry orders - BUY1 and BUY2.
With pyramiding set to 1, it executes BUY2
only after the BUY1
order is closed, not while the latter is still open.
Test scrip given below
//@version=4
strategy(title=Double Strategy Order Check
, overlay=true, pyramiding=1)
startDate = input(title=Start Date
, type=input.integer, defval=1, minval=1, maxval=31)
startMonth = input(title=Start Month
, type=input.integer, defval=1, minval=1, maxval=12)
startYear = input(title=Start Year
, type=input.integer, defval=2010, minval=1800, maxval=2100)
inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))
rsi14 = rsi(close, 14)
sma100 = sma(close, 100)
sma200 = sma(close, 200)
bought = strategy.position_size[0] > strategy.position_size[1]
since_entry = barssince(bought)
firstorder = close > sma100
secondorder = close > sma200
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)