The unrealised profit or loss of the open position at the current price.
strategy.openprofit is a series float. It marks the open trades to the current close, so it moves with the price and drops to 0 when the position closes, at which point the amount moves into net profit.
Type
series float
Remarks
- On a live bar it follows every tick, so avoid using it for a one-time decision before the bar has closed.
- It is 0 while flat. When a trade closes, its result leaves open profit and moves into
strategy.netprofiton the same bar the exit fills, so the sum of the two does not jump.
Example
//@version=6
strategy("Open profit limits", overlay = true, initial_capital = 10000)
if ta.crossover(close, ta.sma(close, 20))
strategy.entry("Long", strategy.long, qty = 10)
if strategy.openprofit > 500 or strategy.openprofit < -300
strategy.close_all(comment = "limit hit")
plot(strategy.openprofit, "Open profit", color.orange, style = plot.style_area)See also
strategy.netprofitstrategy.equitystrategy.position_sizestrategy.openprofit_percentstrategy.position_avg_price
Runs on Sidechair