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
Buy Signal not meet criteria after updating to 2021.1 release due to pandas upgrade #4382
Comments
qtpylib was not touched in months, however other libraries are upgraded all the time. I would not know of any that can cause a differently calculated indicator - nor have i ever heared about that before |
Thanks for your response. Its very strange, i'm sure it happened after update last version from 2020.12 I haven't modified strategy and I'm using BB indicator for buy signal. Freqtrade detects buy signal when criteria is not meet. Well I'm going to investigate in deep. Thanks |
Can you run a version of the bot from 2020.12 and 2021.1 with the exact same config and strategy file to verify the possible different behaviour (try backtesting and dry mode)? |
Yes, I'm going to test this, but I can confirm that no changes have been made in config and strategy. |
Hi, a few days ago I seemed to have faced the same problem but I thought it was impossible and I did not give it much importance, I also use BB and RSI, however I can not assure it but I will be more alert in future buy signals and if there is a problem I will report it here. I am using version 2020.12 and update all libraries to the latest version at the time of updating to version 2020.12 |
I also noticed the issue and I'm able to reproduce it easily.
in my case, the strategy uses Bollinger bands as
I added a line to print the lower band column in populate_buy_trend and the numbers I saw were different, the old version gave correct data. I can provide more logs as needed. |
as said above, qtpylib was not changed, and had it's last change 5 months ago (you can check that yourself in https://github.com/freqtrade/freqtrade/tree/develop/freqtrade/vendor). What has been changed are dependencies (specifically pandas / numpy), so you can try and downgrade these to the old versions one by one. |
Hi, I did some further investigations to confirm which version's data is to be considered correct, here is what I did:
And here's the new 2021.1
Notice how the Bollinger band upper, lower, and mid bands are all the same value which can't be right. I also confirmed the values from 2020.12 by comparing with tradingview I understand that qtpylib was not updated, but I'm just trying to figure out why my strategy started misfiring after the new update. I hope this helps, and keep up the good work. |
Please do the test i explained above - take one version (say 2020.12) - install all dependencies as they are. Ipdate freqtrade to 2021.1 - but do NOT upgrade dependencies (that's easy for a normally installed version - do a git pull - without running setup.sh or something similar). If that's ok - then upgrade (one by one) the dependencies to the versions specified in requirements.txt (best start with pandas and numpy - as i suspect it's one of these as they are the most relevant for calculations in general). This will help you identify which of the dependencies causes this. |
I'm pending to do the test with 2020.12 version. I will come back with results. But I also have confirmed that BB values are not correct in 2021.1 version. Comparing trading view & buy positions , buy signal is ever thrown at middle band. |
I did a slightly modified version of the test and narrowed down that pandas 1.2.2 is responsible for the issue with Bollinger bands. here's what I did in details.
|
the big question is - which of the versions of pandas in between this (there should be The big suspect is obviously be 1.2.0 - beeing a bigger release than the 2 bugfix releases, and the changelog has some relevant points:
and
To further investigate this, i think you'll have to "untie" this problem from freqtrade (you've just shown that it's not freqtrade that's causing it anyway) - and investigate this with "pandas only" methods to be able to bug-report against the pandas repository. what does a manually calculated bollinger band tell you when doing this same comparison? should be as simple as dataframe['middleband'] = dataframe['close'].rolling(window).mean()
rolling_std = dataframe['close'].rolling(window).std()
dataframe['upperband'] = dataframe['middleband'] + (2 * rolling_std)
dataframe['lowerband'] = dataframe['middleband'] - (2 * rolling_std) While this won't return exactly the same as the default qtpylib version (which uses typicalprice in most examples) - it should still give different results between the 2 versions. |
Based on the above, it's related to the pandas update to pandas 1.2 (which does list some changes to how mean() and std is calculated). Apparently it's kindof an expected issue with pandas (pandas-dev/pandas#39872, pandas-dev/pandas#37051) - but without providing any workaround or solution other than downgrading. |
but do you lose any fix between upgrading? Could we not multiple all of the existing data by 1000 then divide the output once the calculation is done? |
You can do that for sure, but it's a fix everyone needs to apply within their strategy, not something that'll be done automatically. |
Following up on the First version that introduced the BB issue, I tested pandas 1.1.5 (used in freqtrade 2020.12), 1.2.0rc0, and up to 1.2.2 All versions after 1.1.5 had wrong values for the upper/lower BBs for pairs with low prices. I will try to put together a case with Pandas, but I don't see this getting fixed soon. I'm wondering if we can consider rolling back to Pandas 1.1.5 (not sure about other dependencies) for the benefit of the freqtrade community until the issue with pandas is resolved. |
well the "case" for pandas is in the 2 issues i linked above - but reading through these it doesn't seem like they consider this as a problem, but as a feature ... downgrading is a possibility in theory - but assuming they'll never fix this as they don't consider it a bug - at what point can we upgrade again to get new features / speed improvements / whatever ... ? in general, pandas will work fine with non-BTC pairs - which (from reading on discord) seems to be more common anyway... |
I am not observing this behavior with dev branch + all pandas versions and using low value BTC pairs. [edit] I wasn't looking at the full precision. After displaying the full float, it appears the bands are being calculated correctly. |
@robcaulk how are you calculating bollinger bands? it's a quite simple, standard indicator, which is available in basically every library (qtpylib, ta-lib, ...) - not all use pandas for these calculations. |
I tested both qtpylib and ta-lib with pandas 1.1.5 and pandas 1.2.2. I am running Ubuntu 18.04. The "low value pairs" are roughly 1e-5 btc. In all cases I did not observe the described problem :-/ |
Hey dude this is brilliant. I am somewhat new to pandas and so I didn't really know how to accomplish what you suggested. but I finally figured it out and I actually tend to like this. it allows you to use to latest and greatest and still salvage a strategy that utilizes Bollinger Bands and probably any other strategy that may rel averages and std using btc and cheap coins. but in case the next person is like ME who was reading this and had no idea how to implement it here is how I got it to work. Obviously some precision is lost but I think its good enough: dataframe['open'] = dataframe['open'].apply(lambda x: x*1000)
dataframe['close'] = dataframe['close'].apply(lambda x: x*1000)
dataframe['high'] = dataframe['high'].apply(lambda x: x*1000)
dataframe['low'] = dataframe['low'].apply(lambda x: x*1000)
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
dataframe['bb_lowerband2'] = bollinger['lower']/1000
dataframe['bb_middleband2'] = bollinger['mid']/1000
dataframe['bb_upperband2'] = bollinger['upper']/1000
dataframe['open'] = dataframe['open'].apply(lambda x: x/1000)
dataframe['close'] = dataframe['close'].apply(lambda x: x/1000)
dataframe['high'] = dataframe['high'].apply(lambda x: x/1000)
dataframe['low'] = dataframe['low'].apply(lambda x: x/1000) |
considering that the precision is around e-16, you'll not lose much as the lowest price i've seen on an exchange is e-8 (they usually don't support any lower precision than e-6 ...) - so you should be fine. The probably better method for bollinger bands might be to use |
@xmatthias thanks for this alternative as well! |
This is how to use
|
Dude thanks this is helpful!! What is the window that it calculates from? 20? |
@skhalsa10 I don't actually know what windows are, but there's one more argument called |
it's quite unfortunate that the ta-lib documentation is quite lacking in many regards. matype will (most likely) be either using SMA or EMA (or something else) ... but without documentation what each type(numbe) means - it'll be rather difficult to deviate from the default. |
@samgermain weird, I tried using ta.BBANDS and it doesn't work for me as expected. for small values it gives the same number (I'm keeping the "incorrect" pandas version - in particular 1.2.3 and my TA-lib version is 0.4.19). and test_talib_bollingerbands_near_zero_values is failing for me. what I might be missing? |
if the ta-lib test fails, then you installed ta-lib wrongly. We need to compile the C dependency with a small change to have it work for the very low numbers BTC pairs generate. |
@xmatthias hmmmm, you mean this one, right? |
this simply means that you assigned something to "close" - which you really shouldn't. |
@xmatthias I just uninstalled ta-lib and re-installed it using install_ta-lib.sh and still no luck, the test is failing. any suggestion? btw it looks to me that it needs to be executed from the build_helpers folder otherwise it logically fails with
got it |
make sure to uninstall the C level dependency as well, not just the python library - otherwise the installation will not really do much ... |
sure. what I did is
and then run |
well you'll need to remove both the python dep - as well as the c library. When i was in a similar hole - i removed it all (first C, then |
tried this several times no luck. oh boy that's quite annoying. and I'm pretty sure that I've done ta-lib installation as instructed from the first time. oh well. so far the workaround with BB for me is the following:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hi wr0ngc0degen / Team, the workaround with BB was the same wr0ngc0degen did.
|
Closing this as the update to pandas 1.3.0 (#5240) finally fixes this upstream bug release-log link. |
Hi,
After updating bot to 2021.1 version, a strategy that worked well before , right now is not working properly, throwing buy signals that doesn't meet criteria.
After install bot began to buy pairs and this was not the normal behaviour of this strategy.
Buy signal is using qtpylib and Bollinger bands and seems that is not calculating this indicator properly.
Has been an update of this library in last release?
Thanks for your support.
The text was updated successfully, but these errors were encountered: