Pairs trade opening priority
Describe your environment
(if applicable)
- Operating system: ____
- Python Version: _____ (
python -V) - CCXT version: _____ (
pip freeze | grep ccxt) - Freqtrade Version: ____ (
freqtrade -Vordocker-compose run --rm freqtrade -Vfor Freqtrade running in docker)
Describe the enhancement
Sometimes it could be useful to order pairs after dataframe analysis for each pair is done (probably based on some indicator or whatever).
Let's imagine that target indicator is "probability of profit" for a pair during the following K candles, for instance predicted by some Machine Learning technique. Someone may want to open trades in max-to-min predicted probability order to maximize expected wins / by expected return based on predicted probability and position size to maximize expected capital growth / whatever else.
Currently there is no clear way to provide "priority" information out of the strategy so the bot will know which pair to enter first. One approach I can imagine right now is to override analyze(self, pairs: List[str]) somehow like:
from queue import PriorityQueue
def analyze(self, pairs: List[str]) -> None:
priority_queue = PriorityQueue()
while pairs:
pair = pairs.pop(0)
pair_priority = 0.0
self.analyze_pair(pair)
analyzed_df, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)
if not analyzed_df.empty:
latest_candle = analyzed_df.iloc[-1].squeeze()
pair_priority = latest_candle[PRIORITY_SIGNAL_COLUMN]
priority_queue.put((pair_priority, pair))
while not priority_queue.empty():
best_priority, best_pair = priority_queue.get()
pairs.append(best_pair)
or just simply .sort() pairs list inplace based on some column calculated in populate_indicators. But is definitely not a straightforward and potentially dangerous approach as it is based on knowledge of bot cycle internals.
What I imagine could be useful is change the IStrategy interface so there will be a point to explicitly provide priorities for the bot cycle and order pairs before enter_positions. This method could be optional to override with default return value of 0.0 so by default there will not be any specific ordering and everything will work exactly how it works right now.
Source: freqtrade/freqtrade