Sidechair

strategy.avg_losing_trade

Browse the reference

The average loss of the losing closed trades in the account currency.

Try it in the editor

strategy.avg_losing_trade is a series float: gross loss divided by the number of losing trades, as a positive number. It is na while there is no loser.

Type

series float

Remarks

Example

Pine ScriptSize the stop from the average loserOpen in editor
//@version=6
strategy("Stop from average loss", overlay = true, initial_capital = 10000)
avgLossPerShare = strategy.avg_losing_trade / 10
stopDistance = na(avgLossPerShare) ? ta.atr(14) * 2 : avgLossPerShare
if ta.crossover(close, ta.sma(close, 20))
    strategy.entry("Long", strategy.long, qty = 10)
    strategy.exit("Stop", "Long", stop = close - stopDistance)
plot(strategy.avg_losing_trade, "Average loss", color.red, display = display.data_window)

See also

Runs on Sidechair