Sidechair

strategy.max_contracts_held_long

Browse the reference

The largest long position size the strategy has held so far.

Try it in the editor

strategy.max_contracts_held_long is a series float: the highest positive value strategy.position_size has reached. It is 0 if the strategy never went long.

Type

series float

Remarks

  • It only grows.
  • It never falls when the position closes, so it cannot tell you the current size. Read strategy.position_size for that.

Example

Pine ScriptLongest side of a two-way systemOpen in editor
//@version=6
strategy("Long peak size", overlay = true, pyramiding = 2, initial_capital = 10000)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long, qty = 5)
if ta.crossunder(fast, slow)
    strategy.entry("Short", strategy.short, qty = 3)
plot(strategy.max_contracts_held_long, "Largest long", color.green, style = plot.style_stepline)
plot(strategy.max_contracts_held_short, "Largest short", color.red, style = plot.style_stepline)

See also

Runs on Sidechair