Max drawdown calc

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #243079 quote
    robertogozzi
    Moderator
    Master

    This code calculates both DrawDown and RunUp and their ratio, butyou have to add it to one of your strategies, not indicators:

    // DrawDown & RunUp  (abridged)
    //
    ONCE Capital  = 10000
    ONCE MinPoint = Capital
    ONCE MaxPoint = 0
    ONCE MaxRU    = 0
    ONCE MaxDD    = 0
    //------------------------------------------
    //       EQUITY
    Equity        = Capital + StrategyProfit
    TempProfit    = PositionPerf * PositionPrice / PipSize * PipValue //   / abs(CountOfPosition)
    TempEquity    = Equity + TempProfit
    //------------------------------------------
    //       DrawDown
    MaxPoint      = max(MaxPoint,TempEquity)
    DD            = MaxPoint - TempEquity
    MaxDD         = max(MaxDD,DD)
    DDperc        = MaxDD * 100 / Capital
    //
    //------------------------------------------
    //       RunUp
    MinPoint      = min(MinPoint,TempEquity)
    RU            = TempEquity - MinPoint
    MaxRU         = max(MaxRU,RU)
    RUperc        = MaxRU * 100 / Capital
    //------------------------------------------
    //       DD/RU ratio
    DDRUratio     = (MaxDD / MaxRU) * 100
    //------------------------------------------

    You only have to set your Capital, in place of 10000.

    LucasBest thanked this post
    #243083 quote
    fifi743
    Participant
    Master

    @robertogozzi Isn’t there a mistake on line 24?

    MaxRU         = min(MaxRU,RU)

    #243089 quote
    robertogozzi
    Moderator
    Master

    No, 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:

    // DrawDown & RunUp
    //
    ONCE Capital  = 100000
    ONCE MinPoint = Capital
    ONCE MaxPoint = 0
    ONCE MaxRU    = 0
    ONCE MaxDD    = 0
    //------------------------------------------
    //       EQUITY
    Equity        = Capital + StrategyProfit
    TempProfit    = PositionPerf * PositionPrice / PipSize * PipValue //   / abs(CountOfPosition)
    TempEquity    = Equity + TempProfit
    //------------------------------------------
    //       DrawDown
    MaxPoint      = max(MaxPoint,TempEquity)
    DD            = MaxPoint - TempEquity
    MaxDD         = max(MaxDD,DD)
    DDperc        = MaxDD * 100 / Capital
    //
    //------------------------------------------
    //       RunUp
    MinPoint      = min(MinPoint,TempEquity)
    RU            = TempEquity - MinPoint
    MaxRU         = max(MaxRU,RU)
    RUperc        = MaxRU * 100 / Capital
    //------------------------------------------
    //       DD/RU ratio
    DDRUratio     = (MaxDD / MaxRU) * 100
    //------------------------------------------
    
    ONCE Punti = 50*PipSize
    ONCE N     = 5
    ONCE SL    = 100*PipSize
    Entrata    = highest[N](high[1]) + Punti
    IF (close > Entrata) AND Not OnMarket THEN
       BUY 1 Contract at Market
       StopLoss = min(SL,abs(close - (low[1] - 1*PipSize)))
       x        = low[1] - 1*PipSize
       SET STOP   LOSS   StopLoss
       SET TARGET PROFIT StopLoss * 2
    ENDIF
    graph MaxRU AS "RunUP" coloured("Green")
    graph MaxDD AS "DrawDOWN" coloured("Red")
    fifi743, justisan and Iván González thanked this post
    #252724 quote
    SnorreDK
    Participant
    Junior

    @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?

    #252725 quote
    robertogozzi
    Moderator
    Master

    Same ast the code above, the do match!

    #252730 quote
    SnorreDK
    Participant
    Junior
    Same 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!

    #252975 quote
    robertogozzi
    Moderator
    Master
    You 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).
Viewing 7 posts - 16 through 22 (of 22 total)
  • You must be logged in to reply to this topic.

Max drawdown calc


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Stef @stef Participant
Summary

This topic contains 21 replies,
has 4 voices, and was last updated by robertogozzi
3 months, 2 weeks ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/22/2016
Status: Active
Attachments: 4 files
Logo Logo
Loading...