The number of closed trades that lost money.
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
- Winning, losing and break-even trades add up to
strategy.closedtrades. - A trade that closes at exactly zero profit counts in neither
strategy.wintradesnor this count; seestrategy.eventrades. It is a running total, so a losing streak needs a counter of your own.
Example
//@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
strategy.wintradesstrategy.eventradesstrategy.closedtradesstrategy.grosslossstrategy.avg_losing_trade
Runs on Sidechair