-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Initial position adjustment support (DCA) #6079
Conversation
No backtesting support.
…ders after first buy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty darn good job 👍
I'm sure we'll discover some edge-cases as more people start using this - but for the moment i'd not know anything more to do on this PR.
LGTM 👍
# Total stake for this trade would be 1 + 1.25 + 1.5 + 1.75 = 5.5x of the initial allowed stake. | ||
# That is why max_dca_multiplier is 5.5 | ||
# Hope you have a deep wallet! | ||
if 0 < count_of_buys <= self.max_dca_orders: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job to both of you! I have a question about the select_filled_orders
method.
Wouldn't this condition trigger multiple orders if the first order doesn't get filled right away? I think this count should include the potential pyramidal orders created in the last cycle.
As far as I understand, we're counting just filled orders with these statuses which would not select orders we might have already placed at this level and which are still open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read the documentation that was added as part of this PR.
this callback will not be called if a order is open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed it! It might be worth adding it to the function docstring as well.
Will we be able to do partial trading now? How to use it, can you share a detailed usage or a sample study? thank you. |
This is a nice feature, but i don't think the example is very useful because profitable trades will only have a small stake, which means only small profits on these trades and losing trades will have high stakes, which means much higher losses are possible. |
Point of example is to demonstrate how to use this feature. Profitability of samples is really out of scope of technical documentation. |
Ok, but do you think we can use additional buy signals to adjust positions? |
Anything is possible if you know how to code it |
Signal adjustment callback runs on each candle. You may access dataframe from this callback and see if last candle has your signal. See here https://www.freqtrade.io/en/stable/strategy-advanced/#dataframe-access |
Thank you for your reply, this was very helpful. |
This post on Discord may help you @incrementby1. As an aside, backtesting is broken if you remove the current_profit check @xmatthias |
That link kindof leads to the rules channel ... so not "quite" sure what you're trying to point me to ... |
Oh sorry, its the Freqtrade Discord server, my post regarding using buy signals (or other dataframe signals) to trigger DCA buys individually. I'll fill in a github issue report regarding the backtesting. |
That link doesn't open properly, yet it's the link copied directly from the post (in the DCA thread). Odd... Anyway, do a search for DCATest2_fixed.py on Discord. |
A note to those who might read it later - "backtesting is broken if you remove the current_profit check" is wrong, everything works as expected. If you remove current_profit then you'll just end up buying until you run out of money. It's the responsibility of adjust_trade_position to decide if it's the right moment to buy more - if you don't check your current profit then you better check something else and do not return a stake amount if you don't want to buy. |
True, but there is no difference between that and failing the current_profit check on all DCA buys. In backtesting this would fail, in live/dry it behaves correctly as it buys as much as it can with DCA and holds the trades open. |
@xataxxx If you think backtesting isn't broken, run this simple strategy that just buys 3 times then sells and repeats. It should not (IMO) immdiately close trades with a profit of -0.2%, the user is in complete control with max_dca_orders and max_dca_multiplier, it should just buy the max it can and leave the trade open just like it does in live or dry. I'm concerned this is highlightng an underlying logical issue that might show itself if a current_profit check were to fail for each DCA buy, and if adjust_trade_position() is called once per candle and current_profit is the open rate of the next candle this is entirely possible. I may of course be misinterpreting things, but maybe you could explain why this behaviour shows it 'works as expected'? |
If you think something is broken, please open an issue with all necessary details (this includes a simple strategy to reproduce the problem, but also output that's produced by it, the command used for this (if necessary some config), and maybe a description what you'd expect and what happened. Based on the above comment, you'd expect us to first investigate what's actually happening, while then comparing it what you think would happen - which will quite frankly - simply waste our time. |
Just for info for future readers, @perkmeister issue was actually caused by another tiny temporary bug in codebase that disabled adjust_trade_position completely, not in the actual backtesting functionality. |
Actually as we said there were 2 problems, it seems the zero length trade issue was an issue and has been fixed in the latest update (only a few days ago it seems), and the latest update has a minor bug with the adjust_trade_position being at config level not strategy level. |
Summary
Implement position adjustment / stacking / multiple buys of the same pair within a single trade.
Partly solve the issue: #2183 and #1519
Quick changelog
adjust_trade_position
to strategy that can indicate if should buy more and how much.position_adjustment_enable
strategy parameter to enable this feature.What's new?
Implement ability for strategy to buy more of an already opened trade.
The most common scenario for this would be DCA (Dollar Cost Averaging).
The theory is that your buys signals, while good, sometimes still produce trades that first go down X% and then rise to the profit. With DCA you can buy more of the same coin when it's gone down Y% to increase your stake and lower your average open price. This results in higher probability to reach profit AND faster trade times. It can also produce bigger and more hurtful stoplosses.
Done list:
TODO List: