The id of the entry order that opened the current position, or an empty string when flat.
strategy.position_entry_name is a series string. It holds the id you gave to strategy.entry for the first trade of the position.
Type
series string
Remarks
- With pyramiding it names only the original entry, not later adds. Use
strategy.opentrades.entry_id(n)to read each open trade's id. - Ids are case sensitive: compare against the exact text you passed to
strategy.entry. The value is an empty string, not na, while the strategy is flat.
Example
//@version=6
strategy("Which setup is open", overlay = true)
breakout = close > ta.highest(high, 20)[1]
pullback = ta.crossover(close, ta.sma(close, 20))
if strategy.position_size == 0
if breakout
strategy.entry("Breakout", strategy.long)
else if pullback
strategy.entry("Pullback", strategy.long)
if ta.crossunder(close, ta.sma(close, 50))
strategy.close_all()
isBreakout = strategy.position_entry_name == "Breakout"
isPullback = strategy.position_entry_name == "Pullback"
bgcolor(isBreakout ? color.new(color.blue, 88) : isPullback ? color.new(color.orange, 88) : na)See also
Runs on Sidechair