strategy.opentrades.max_drawdown() - Pine Script Function
strategy.opentrades.max_drawdown()
Section titled “strategy.opentrades.max_drawdown()”Overview
Section titled “Overview”Returns the maximum drawdown of the open trade, i.e., the maximum possible loss during the trade, expressed in strategy.account_currency.
Syntax
Section titled “Syntax”strategy.opentrades.max_drawdown(trade_num) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| trade_num | series int | The trade number of the open trade. The number of the first trade is zero. |
Remarks
Section titled “Remarks”- The function returns na if trade_num is not in the range: 0 to strategy.closedtrades - 1.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”// Calculates the max trade drawdown valuefor all open trades.//@version=6strategy("`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 == 0strategy.entry("Long", strategy.long)if bar_index % 20 == 0strategy.close("Long")// Get the biggest max trade drawdown value from all of the open trades.maxTradeDrawDown() => maxDrawdown = 0.0for tradeNo = 0 to strategy.opentrades - 1 maxDrawdown :=math.max(maxDrawdown, strategy.opentrades.max_drawdown(tradeNo)) result = maxDrawdownplot(maxTradeDrawDown(), "Biggest max drawdown")