Forums › ProRealTime English forum › ProBuilder support › Max drawdown calc
This code calculates both DrawDown and RunUp and their ratio, butyou have to add it to one of your strategies, not indicators:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
// 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.
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
// 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") |