Add current drawdown in telegram profit command

This commit is contained in:
mrpabloyeah
2025-06-21 12:10:53 +02:00
parent effd989796
commit 2ebc5374f4
3 changed files with 75 additions and 12 deletions

View File

@@ -19,7 +19,12 @@ from freqtrade import __version__
from freqtrade.configuration.timerange import TimeRange
from freqtrade.constants import CANCEL_REASON, DEFAULT_DATAFRAME_COLUMNS, Config
from freqtrade.data.history import load_data
from freqtrade.data.metrics import DrawDownResult, calculate_expectancy, calculate_max_drawdown
from freqtrade.data.metrics import (
DrawDownResult,
calculate_current_drawdown,
calculate_expectancy,
calculate_max_drawdown,
)
from freqtrade.enums import (
CandleType,
ExitCheckTuple,
@@ -612,17 +617,23 @@ class RPC:
expectancy, expectancy_ratio = calculate_expectancy(trades_df)
drawdown = DrawDownResult()
max_drawdown = DrawDownResult()
current_drawdown = DrawDownResult()
if len(trades_df) > 0:
try:
drawdown = calculate_max_drawdown(
max_drawdown = calculate_max_drawdown(
trades_df,
value_col="profit_abs",
date_col="close_date_dt",
starting_balance=starting_balance,
)
except ValueError:
# ValueError if no losing trade.
pass
try:
current_drawdown = calculate_current_drawdown(trades_df, starting_balance)
except ValueError:
pass
profit_all_fiat = (
@@ -673,14 +684,19 @@ class RPC:
"winrate": winrate,
"expectancy": expectancy,
"expectancy_ratio": expectancy_ratio,
"max_drawdown": drawdown.relative_account_drawdown,
"max_drawdown_abs": drawdown.drawdown_abs,
"max_drawdown_start": format_date(drawdown.high_date),
"max_drawdown_start_timestamp": dt_ts_def(drawdown.high_date),
"max_drawdown_end": format_date(drawdown.low_date),
"max_drawdown_end_timestamp": dt_ts_def(drawdown.low_date),
"drawdown_high": drawdown.high_value,
"drawdown_low": drawdown.low_value,
"max_drawdown": max_drawdown.relative_account_drawdown,
"max_drawdown_abs": max_drawdown.drawdown_abs,
"max_drawdown_start": format_date(max_drawdown.high_date),
"max_drawdown_start_timestamp": dt_ts_def(max_drawdown.high_date),
"max_drawdown_end": format_date(max_drawdown.low_date),
"max_drawdown_end_timestamp": dt_ts_def(max_drawdown.low_date),
"drawdown_high": max_drawdown.high_value,
"drawdown_low": max_drawdown.low_value,
"current_drawdown": current_drawdown.relative_account_drawdown,
"current_drawdown_abs": current_drawdown.drawdown_abs,
"current_drawdown_high": current_drawdown.high_value,
"current_drawdown_start": format_date(current_drawdown.high_date),
"current_drawdown_start_timestamp": dt_ts_def(current_drawdown.high_date),
"trading_volume": trading_volume,
"bot_start_timestamp": dt_ts_def(bot_start, 0),
"bot_start_date": format_date(bot_start),

View File

@@ -1085,6 +1085,10 @@ class Telegram(RPCHandler):
f"({fmt_coin(stats['drawdown_high'], stake_cur)})`\n"
f" to `{stats['max_drawdown_end']} "
f"({fmt_coin(stats['drawdown_low'], stake_cur)})`\n"
f"*Current Drawdown:* `{stats['current_drawdown']:.2%} "
f"({fmt_coin(stats['current_drawdown_abs'], stake_cur)})`\n"
f" from `{stats['current_drawdown_start']} "
f"({fmt_coin(stats['current_drawdown_high'], stake_cur)})`\n"
)
await self._send_msg(
markdown_msg,