Sidechair

strategy.openprofit

Browse the reference

The unrealised profit or loss of the open position at the current price.

Try it in the editor

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.netprofit on the same bar the exit fills, so the sum of the two does not jump.

Example

Pine ScriptClose when the open trade hits a money limitOpen in editor
//@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

Runs on Sidechair