Sidechair

strategy.losstrades

Browse the reference

The number of closed trades that lost money.

Try it in the editor

strategy.losstrades is a series int. A trade counts when it is closed and its result after commission is below 0.

Type

series int

Remarks

Example

Pine ScriptStop after five lossesOpen in editor
//@version=6
strategy("Loss limit", overlay = true, initial_capital = 10000)
tooManyLosses = strategy.losstrades >= 5
if ta.crossover(ta.sma(close, 10), ta.sma(close, 30)) and not tooManyLosses
    strategy.entry("Long", strategy.long, qty = 10)
if ta.crossunder(ta.sma(close, 10), ta.sma(close, 30))
    strategy.close("Long")
plot(strategy.losstrades, "Losing trades", color.red, style = plot.style_stepline)
bgcolor(tooManyLosses ? color.new(color.red, 90) : na)

See also

Runs on Sidechair