Max drawdown calc
Forums › ProRealTime English forum › ProBuilder support › Max drawdown calc
- This topic has 21 replies, 4 voices, and was last updated 1 month ago by
robertogozzi.
-
-
01/24/2025 at 7:51 PM #243079
This code calculates both DrawDown and RunUp and their ratio, butyou have to add it to one of your strategies, not indicators:
1234567891011121314151617181920212223242526272829// DrawDown & RunUp (abridged)//ONCE Capital = 10000ONCE MinPoint = CapitalONCE MaxPoint = 0ONCE MaxRU = 0ONCE MaxDD = 0//------------------------------------------// EQUITYEquity = Capital + StrategyProfitTempProfit = PositionPerf * PositionPrice / PipSize * PipValue // / abs(CountOfPosition)TempEquity = Equity + TempProfit//------------------------------------------// DrawDownMaxPoint = max(MaxPoint,TempEquity)DD = MaxPoint - TempEquityMaxDD = max(MaxDD,DD)DDperc = MaxDD * 100 / Capital////------------------------------------------// RunUpMinPoint = min(MinPoint,TempEquity)RU = TempEquity - MinPointMaxRU = max(MaxRU,RU)RUperc = MaxRU * 100 / Capital//------------------------------------------// DD/RU ratioDDRUratio = (MaxDD / MaxRU) * 100//------------------------------------------You only have to set your Capital, in place of 10000.
1 user thanked author for this post.
01/25/2025 at 9:09 AM #24308301/25/2025 at 4:34 PM #243089No, as we always have to store the highest value, both for RunUP and DrawDOW, this code matches ProRealTime calculations (on Dax, DailyTF) as shown in the attached pic:
12345678910111213141516171819202122232425262728293031323334353637383940414243// DrawDown & RunUp//ONCE Capital = 100000ONCE MinPoint = CapitalONCE MaxPoint = 0ONCE MaxRU = 0ONCE MaxDD = 0//------------------------------------------// EQUITYEquity = Capital + StrategyProfitTempProfit = PositionPerf * PositionPrice / PipSize * PipValue // / abs(CountOfPosition)TempEquity = Equity + TempProfit//------------------------------------------// DrawDownMaxPoint = max(MaxPoint,TempEquity)DD = MaxPoint - TempEquityMaxDD = max(MaxDD,DD)DDperc = MaxDD * 100 / Capital////------------------------------------------// RunUpMinPoint = min(MinPoint,TempEquity)RU = TempEquity - MinPointMaxRU = max(MaxRU,RU)RUperc = MaxRU * 100 / Capital//------------------------------------------// DD/RU ratioDDRUratio = (MaxDD / MaxRU) * 100//------------------------------------------ONCE Punti = 50*PipSizeONCE N = 5ONCE SL = 100*PipSizeEntrata = highest[N](high[1]) + PuntiIF (close > Entrata) AND Not OnMarket THENBUY 1 Contract at MarketStopLoss = min(SL,abs(close - (low[1] - 1*PipSize)))x = low[1] - 1*PipSizeSET STOP LOSS StopLossSET TARGET PROFIT StopLoss * 2ENDIFgraph MaxRU AS "RunUP" coloured("Green")graph MaxDD AS "DrawDOWN" coloured("Red")10/18/2025 at 3:10 PM #252724@Nicolas, tx for that!
I wonder how they (PRT) calculate their max drawdown %.
I did some comparisons on different instruments – see attached.
It looks like my calculations are 85%+ accurate on average – or at least 85%+ the same as theirs.
Interesting if you look at the 2nd and 4th results – at least we are both consistent which is a good sign.
Stef
How do u export dd-data?
10/18/2025 at 5:29 PM #252725Same ast the code above, the do match!
10/19/2025 at 8:47 AM #252730Same ast the code above, the do match!
How do I get time-series Drawdown into a ProRealTime CSV export?
I’ve added your code to my strategy and it displays correctly on the chart in ProRealTime—great!
But I can’t figure out how to include Drawdown in my CSV export.What I’m doing now
-
Export path: Detailed report → Closed positions list → Export CSV
-
That CSV doesn’t include any Drawdown fields.
What I actually need
-
Not a single fixed “Max DD” value, but a Drawdown time series so I can analyze how DD evolves over time and compute:
-
Max DD between two dates,
-
Max DD for another date range, etc., all based on the export.
-
Ideal CSV columns (any equivalent works):
-
Date/Time,Equity(or Balance/NetLiquidation), Running Peak, Drawdown (amount), Drawdown (%).
With those I can filter any interval and calculate max DD for that window.
Question
-
Which exact menu/report should I use to export a CSV that contains the equity curve and/or running drawdown (daily or bar-by-bar)?
-
Is there a column/checkbox I’m missing to add Drawdown to the export?
If PRT can’t export DD directly
-
What’s the best workaround? For example:
-
Export the equity curve and compute DD from equity vs. running peak, or
-
Log
strategyprofit/ equity and a running peak from code into custom variables so they appear in a CSV.
-
Current path used: Detailed report → Closed positions list (CSV).
Looking for the precise click path (and settings) to get a time-series drawdown out. Thanks!10/23/2025 at 12:53 PM #252975You may get some data from the backtest:
- entry price
- exit price
- outcome
- type of trade (long or short)
then you have to get the OHLC data from the chart (you can find posts on how to get it, which is not as straightforward, though, at https://www.prorealcode.com/topic/exporter-les-donnees-historiques-ohlc/#post-250046).
Once you have that data I think a spreadsheet app, such as eXcel, might be able to recalculate the drawdown, maybe with the help of Visual Basic for Applications (VBA).
-
-
AuthorPosts
