Sidechair

strategy.wintrades

Browse the reference

The number of closed trades that made a profit.

Try it in the editor

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

Type

series int

Remarks

  • Divide it by strategy.closedtrades for the win rate, after checking that closedtrades is not 0.
  • strategy.wintrades divided by strategy.closedtrades is the win rate. A high win rate can still lose money when the losers are larger than the winners.

Example

Pine ScriptWin rateOpen in editor
//@version=6
strategy("Win rate", 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")
winRate = strategy.closedtrades > 0 ? strategy.wintrades / strategy.closedtrades * 100 : na
plot(winRate, "Win rate %", color.green)
hline(50, "Half", color.gray)

See also

Runs on Sidechair