From ab7f8b3a0fb2da6379b4af1d7dfc9cf7fecb037e Mon Sep 17 00:00:00 2001 From: Joe Schr <8218910+TheJoeSchr@users.noreply.github.com> Date: Fri, 17 May 2024 15:49:53 +0200 Subject: [PATCH] `imbalance_ratio`: use ratio instead of percentage --- docs/advanced-orderflow.md | 2 +- freqtrade/constants.py | 2 +- freqtrade/data/converter/orderflow.py | 8 ++++---- tests/data/test_converter_public_trades.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/advanced-orderflow.md b/docs/advanced-orderflow.md index edbde1ec7..d2e76d134 100644 --- a/docs/advanced-orderflow.md +++ b/docs/advanced-orderflow.md @@ -24,7 +24,7 @@ This guide walks you through utilizing public trade data for advanced orderflow "scale": 0.5, "stacked_imbalance_range": 3, // needs at least this amount of imbalance next to each other "imbalance_volume": 1, // filters out below - "imbalance_ratio": 300 // filters out ratio lower than + "imbalance_ratio": 3 // filters out ratio lower than }, ``` diff --git a/freqtrade/constants.py b/freqtrade/constants.py index 24caa624a..919a991bb 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -531,7 +531,7 @@ CONF_SCHEMA = { "scale": {"type": "number", "minimum": 0.0}, "stacked_imbalance_range": {"type": "number"}, "imbalance_volume": {"type": "number"}, - "imbalance_ratio": {"type": "number"}, + "imbalance_ratio": {"type": "number", "minimum": 0.0}, }, }, }, diff --git a/freqtrade/data/converter/orderflow.py b/freqtrade/data/converter/orderflow.py index 793e43875..c48e95354 100644 --- a/freqtrade/data/converter/orderflow.py +++ b/freqtrade/data/converter/orderflow.py @@ -211,16 +211,16 @@ def trades_to_volumeprofile_with_total_delta_bid_ask(trades: pd.DataFrame, scale def trades_orderflow_to_imbalances(df: pd.DataFrame, imbalance_ratio: int, imbalance_volume: int): """ :param df: dataframes with bid and ask - :param imbalance_ratio: imbalance_ratio e.g. 300 - :param imbalance_volume: imbalance volume e.g. 3) + :param imbalance_ratio: imbalance_ratio e.g. 3 + :param imbalance_volume: imbalance volume e.g. 10 :return: dataframe with bid and ask imbalance """ bid = df.bid ask = df.ask.shift(-1) - bid_imbalance = (bid / ask) > (imbalance_ratio / 100) + bid_imbalance = (bid / ask) > (imbalance_ratio) # overwrite bid_imbalance with False if volume is not big enough bid_imbalance_filtered = np.where(df.total_volume < imbalance_volume, False, bid_imbalance) - ask_imbalance = (ask / bid) > (imbalance_ratio / 100) + ask_imbalance = (ask / bid) > (imbalance_ratio) # overwrite ask_imbalance with False if volume is not big enough ask_imbalance_filtered = np.where(df.total_volume < imbalance_volume, False, ask_imbalance) dataframe = pd.DataFrame( diff --git a/tests/data/test_converter_public_trades.py b/tests/data/test_converter_public_trades.py index 96ba5e7a5..07e17b1b7 100644 --- a/tests/data/test_converter_public_trades.py +++ b/tests/data/test_converter_public_trades.py @@ -92,7 +92,7 @@ def test_public_trades_mock_populate_dataframe_with_trades__check_orderflow( "orderflow": { "scale": 0.005, "imbalance_volume": 0, - "imbalance_ratio": 300, + "imbalance_ratio": 3, "stacked_imbalance_range": 3, }, } @@ -202,7 +202,7 @@ def test_public_trades_trades_mock_populate_dataframe_with_trades__check_trades( "orderflow": { "scale": 0.5, "imbalance_volume": 0, - "imbalance_ratio": 300, + "imbalance_ratio": 3, "stacked_imbalance_range": 3, }, }