New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibility to reverse marginal positions (long/short) at a single candle #9183
Comments
in live, it's an artificial limitation (to some degree) - which could be fixed with 1-2 lines. In backtesting, this is however built into the execution logic, which automatically locks pairs for the duration of the candle (since we check for entries before exits). This leaves the possibility to check for "entries -> exits -> entries" - but then the 2nd entry will no longer be able to exit within this candle - so the 2nd entry behaves different to the initial entry (so we'd need to check "entries -> exits -> entries -> exits" - but even here it's limited, as you could have more than 2 entries per candle i guess). This would introduce semi-infinite loops to backtesting - with a performance impact that in my opinion doesn't justify the usefulnes. If you have some ideas on HOW this can be implemented in backtesting - share your ideas and i'm happy to look at it (ideally to review a PR for it). Otherwise, i don't see this as something we'll look at anytime soon (most likely never). |
Thanks for the very informative comment! I feel, this question is being discussed for a long time. Could you, please, elaborate the phrase "you could have more than 2 entries per candle i guess"? |
That's for static / dataframe based signals - yes - though the 16 combinations are not really relevant, as most would conflict. but for all other (usually more common) exit methods (stoploss, roi, custom_exit, ...) - there's no such thing as collisions, they're always enacted (There's exceptions to this, irrelevant for this issue).
Assuming 1h candles, we're on the 11h candle (stoploss is taken as sample, all above mentioned non-DF exit methods are treated equally). The min. scenarios you'd aim to cover are
Scenarios to ignore due to conflicts (that's the easy part)
That's at minimum 2 iterations you'd have for each candle, each containing
You could also have 5 trades (on different pairs) exiting at the same candle, with 5 new trades entering, 3 on the same pair reversing position, 2 on new pairs - and one of the "reverse position" signals being ignored, as the new pairs are further in front in the pairlist. All of the above logic currently assumes that it's executed exactly once per candle - where executing it twice will have
As this will only benefit a rather small percentage of users, all of this needs to be implemented in a way that's not impacting performance negatively for users that don't need this. |
Aha, as I supposed, I just have not thought about "non-DF" exits. You are right, the things seem rather complex. Currently I don't have enough expertise to suggest working concept/PR, but here's a table of these 16 combinations with corresponding actions, that could seem reasonable (maybe, for future implementations/fixes). Please, feel free to edit/copy it, etc.
EDIT: as there are "non-DF" exits, the word "strange" is not too good, as the case could be quite normal. |
Unfortunately that table is mostly useless (at least for this issue implementation) - as it ignores non-dataframe behavior (which is where most of the complexity is introduced, as you can no longer predict where a trade is going to exit). as long as we stick to "dataframe only" behaviors - behavior is clear - but we can't. One thing to note: |
Yes, logging of SC (soft-collisions) could be reasonable only on -v (or -vv) versbosity levels or just skipped. But logging of HC (hard collisions) as warnings - in my opinion, is vital as they report principal strategy inconsistencies to the user. |
Here's the version 2 of the table - now including "non-DF" exits. Terminology:
Hope this could be useful for further discussions sometimes in the future. |
my 2 cents here : the ability to reverse a marginal position (e.g., futures) from long to short (or vice versa) within the same candle should be handled from config first .. |
Wouldn't it be a simple case of processing the exities first and then the entries? |
Dry/live, yes it's simple. Backtest? Read the replies above. Ofc if you think you can make it work, please do open a PR |
I'm sorry! I didn't know that backtesting was more important than dry/live. Could we consider the open candle, after the signal, as the closing/opening value, for backtest purposes only, not being as precise as necessary? |
once again, read above replies. Matthias already explained the issues. If you think you can provide the solution, please do open a PR. If you only care about dry/live, you can manually unlock the pair. You can read the docs on how to do that |
Describe your environment
(if applicable)
Describe the enhancement
Currently, Freqtrade does not seem to support a rather convenient feature: the ability to reverse a marginal position (e.g., futures) from long to short (or vice versa) within the same candle. For example, in the Binance GUI, this functionality is implemented in a single click of "Reverse" button.
The absence of this feature can be quite disappointing, as it may lead to unnecessary delays and, in some cases, financial losses when a strategy needs to wait for the next candle to open the second half of a reverse transaction. This is particularly impactful on longer timeframes, such as 1h and longer.
As a workaround some people even suggest to launch two FreqTrade instances simalteneously(!)
Additionally, this limitation can lead to confusion during backtesting, as Freqtrade, without issuing any warning in the log, will ignore "Enter long" signal that is placed in the same candle with "Exit short" signal, despite the documentation suggesting that such cases are not forbidden:
(according to this, enter_long should not conflict with exit_short)
Anyway, thanks for the great product!!
The text was updated successfully, but these errors were encountered: