Sidechair

strategy.grossloss

Browse the reference

The sum of the losses of all losing closed trades, as a positive number.

Try it in the editor

strategy.grossloss is a series float: the total of every closed trade that lost money, stated as a positive amount. It never decreases.

Type

series float

Remarks

  • Net profit equals gross profit minus gross loss.
  • Use it as the denominator of a profit factor: strategy.grossprofit / strategy.grossloss, and check for 0 first.
  • It is stored as a positive number, so net profit is strategy.grossprofit minus strategy.grossloss, not plus.

Example

Pine ScriptProfit factorOpen in editor
//@version=6
strategy("Profit factor", initial_capital = 10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
if ta.crossover(ta.sma(close, 10), ta.sma(close, 30))
    strategy.entry("Long", strategy.long)
if ta.crossunder(ta.sma(close, 10), ta.sma(close, 30))
    strategy.close("Long")
profitFactor = strategy.grossloss > 0 ? strategy.grossprofit / strategy.grossloss : na
plot(profitFactor, "Profit factor", color.blue)
hline(1, "Break even", color.gray)

See also

Runs on Sidechair