Skip to content
Algo Trade Analytics Docs

strategy.opentrades.max_drawdown() - Pine Script Function

Returns the maximum drawdown of the open trade, i.e., the maximum possible loss during the trade, expressed in strategy.account_currency.

strategy.opentrades.max_drawdown(trade_num) → series float
NameTypeDescription
trade_numseries intThe trade number of the open trade. The number of the first trade is zero.
  • The function returns na if trade_num is not in the range: 0 to strategy.closedtrades - 1.
// Calculates the max trade drawdown value
for all open trades.//@version=6
strategy("`strategy.opentrades.max_drawdown` Example 2", pyramiding = 100)// Strategy calls to enter long trades every 15 bars and exit long trades every 20 bars.
if bar_index % 15 == 0
strategy.entry("Long", strategy.long)
if bar_index % 20 == 0
strategy.close("Long")// Get the biggest max trade drawdown value from all of the open trades.maxTradeDrawDown() => maxDrawdown = 0.0
for tradeNo = 0 to strategy.opentrades - 1 maxDrawdown :=
math.max(maxDrawdown, strategy.opentrades.max_drawdown(tradeNo)) result = maxDrawdown
plot(maxTradeDrawDown(), "Biggest max drawdown")