
Open-source script In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Just replace le/se with your long/short conditions.
#MAX DRAWDOWN TRADINGVIEW CODE#
I added the iteration number just for fun. 1 This is how you'd code max drawdown for your strategies. Input : an array of floats of arbitrary size (the values we want the DD of) There a 2 functions : "maximum_relative_drawdown" and "maximum_dradown" (and "optimized_maximum_relative_drawdown" and "optimized_maximum_drawdown") with names speaking for themselves. The Trailing Max Drawdown will stop increasing when your account balance becomes equal to your starting account balance. In the example we calculate the maxDDs of the last 10 close values. A Trailing Max Drawdown is the maximum amount of loss that your account can sustain, but it ‘trails’ up, meaning as you accrue profits the Trailing Max Drawdown increases. There are 2 algorithms to calculate maxDD and relative maxDD%, one non optimized needs n*(n - 1)/2 comparisons for a collection of n datas, the other one only needs n-1 comparisons. I didn't find any builtin pinescript way to do it, so here it is. I needed a way to calculate the maxDD% of a serie of datas from an array (the different values of my balance account). It includes TradingView's calculations for Net profit, Total Trades, Percent of Trades Profitable, Profit Factor, Max Drawdown (absolute and percent), and Average Trade (absolute and percent).


Maximum Drawdown and Maximum Relative Drawdown% calculating functions. Hello everyone, Here is a perfectly replicated TradingView backtesting engine condensed into a single library function calculated with arrays.
