Sidechair

strategy.avg_trade

Browse the reference

The average result of a closed trade in the account currency, winners and losers together.

Try it in the editor

strategy.avg_trade is a series float: net profit divided by the number of closed trades. It is na until the first trade closes.

Type

series float

Remarks

Example

Pine ScriptPause when the average trade turns negativeOpen in editor
//@version=6
strategy("Expectancy guard", overlay = true, initial_capital = 10000)
enoughTrades = strategy.closedtrades >= 10
losing = enoughTrades and strategy.avg_trade < 0
if ta.crossover(ta.sma(close, 10), ta.sma(close, 30)) and not losing
    strategy.entry("Long", strategy.long, qty = 10)
if ta.crossunder(ta.sma(close, 10), ta.sma(close, 30))
    strategy.close("Long")
plot(strategy.avg_trade, "Average trade", color.blue, style = plot.style_stepline)
bgcolor(losing ? color.new(color.red, 90) : na)

See also

Runs on Sidechair