[pshaiCmd] Report Maximum Drawdown based on GetBotProfit (for v4 Cloud)

stable
By pshai in Miscellaneous Published November 2021 👁 1,272 views 💬 0 comments

Description

Maximum Drawdown in a Custom Command format, made for educational purposes. The command uses GetBotProfit to get the peak and trough. NOTE: The CC does not work on HTS v3 because of missing commands. The CC was made on and for v4 Cloud version. Usage: CC_ReportMdd() Example output in backtest logs:
--------------------- Report Maximum Drawdown (BINANCEFUTURES_BTC_USDT_PERPETUAL) --------------------- Maximum Drawdown: -7.676 / -1.2154 %
HaasScript
-- Report Maximum Drawdown, based on GetBotProfit
-- Author: pshai


DefineCommand(
    'ReportMdd',
    'Report Maximum Drawdown, based on GetBotProfit'
)

-- inputs
local market = DefineParameter(
    StringType,
    'market',
    'Market ID',
    false,
    PriceMarket()
)

-- locals
local pnl = GetBotProfit(market, true)
local peak = Load('peak', 0)
local trough = Load('trough', 0)
local mdd = Load('mdd', 0)
local mddp = Load('mddp', 0)


-- logic
if pnl > peak then
    peak = pnl
    trough = pnl
elseif pnl < trough then
    trough = pnl

    if trough - peak < mdd then
        mdd = trough - peak
        mddp = peak != 0 and mdd / peak or 0
    end
end

-- memory
Save('peak', peak)
Save('trough', trough)
Save('mdd', mdd)
Save('mddp', mddp)


-- reports
local group = 'Report Maximum Drawdown (' .. market .. ')'
CustomReport('Peak', Round(peak, AmountDecimals()), group)
CustomReport('Trough', Round(trough, AmountDecimals()), group)
CustomReport('Maximum Drawdown', Round(mdd, AmountDecimals()) .. ' / ' .. Round(mddp, 4) .. ' %', group)


DefineOutput(VoidType)

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!