Sidechair

strategy.closedtrades.max_drawdown()

Browse the reference

The worst unrealised loss a closed trade suffered while it was open, in the account currency.

Try it in the editor

strategy.closedtrades.max_drawdown(trade_num) is the lowest point the trade's profit reached between entry and exit, measured against the entry price and using each bar's high and low rather than only closes.

It shows how much heat you took on a trade, including trades that finished in profit, and is the figure to check when you size stops.

Syntax

Pine Script
strategy.closedtrades.max_drawdown(trade_num: series int) -> series float

Arguments

NameTypeDefaultDescription
trade_numseries intrequiredZero-based index of the closed trade. 0 is the first trade the strategy closed and strategy.closedtrades - 1 is the most recent.

Returns

series float: The deepest unrealised loss the trade showed while open, in the account currency. na when the trade does not exist.

Remarks

  • Returns na when trade_num is negative, is not below strategy.closedtrades, or points at a trade that has dropped out of the history (see strategy.closedtrades.first_index).
  • Wrap the value in math.abs when you compare or add these numbers, so the result does not depend on whether you read the drawdown as a loss amount or a signed value.

Example

Pine ScriptDeepest dip of any tradeOpen in editor
//@version=6
strategy("Worst heat", overlay = false)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long)
if ta.crossunder(fast, slow)
    strategy.close("Long")
worst = 0.0
for i = strategy.closedtrades.first_index to strategy.closedtrades - 1
    worst := math.max(worst, math.abs(strategy.closedtrades.max_drawdown(i)))
plot(worst, "Largest trade drawdown", color.red)

See also

Runs on Sidechair