Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Talib and Tulip MFI produce very inaccurate results #1827

Closed
s5m4 opened this issue Jan 31, 2018 · 13 comments
Closed

Talib and Tulip MFI produce very inaccurate results #1827

s5m4 opened this issue Jan 31, 2018 · 13 comments

Comments

@s5m4
Copy link

s5m4 commented Jan 31, 2018

Note: for support questions, please join our Discord server

  • I'm submitting a ...
    [x ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository

  • Action taken (what you did)
    I made a strategy using the tulip MFI (money flow index) indictor, on debugging the strategy in gekko backtesting I realized the MFI results are very far off from the expected results. To investigate further I tried the talilb MFI. Talib and tulib MFI's are both far off expected results and sometimes output the same and sometimes completely different values.

  • Expected result (what you hoped would happen)
    Have MFI indicator output reliable results, as displayed by the indicators on the exchange where I got my backtesting data from. Bitfinex uses trading-view.com charts, so I assume they are mostly reliable (don't hesitate to correct me if that's known not to be the case)

  • Actual result (unexpected outcome)
    I compared the values with the values given by the mfi indicator on bitfinex with the same parameters for the very same time frames (candles). I realize the candle-data iself (OHCL) from the exchange do not 100% match the candles available in gekko but pretty much. The mfi results however are far off, sometimes not even remotely related to the expected result.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc)

Backtesting data from bitfinex, EUR-IOT

bitfinex-mfi

console-output

I made a simple "strategy" to make it easier to reproduce:

var log = require('../core/log');
var strat = {};
strat.init = function() {
	var mfiSettings = {
		optInTimePeriod: 14
	}
	/*TULIP*/this.addTulipIndicator('tulip', 'mfi', mfiSettings );
	/*TALIB*/this.addTalibIndicator('talib', 'mfi', mfiSettings );
}
strat.update = function() {}
strat.log = function() {}
strat.check = function(candle) {
	
	console.log('candle moment______:',candle.start);
	console.log('candle.close_______:',candle.close);
	console.log('TULIP MFIresult____:',this.tulipIndicators.tulip.result['result']);
	console.log('TALIB MFIresult____:',this.talibIndicators.talib.result['outReal']);
	console.log(candle);
}
module.exports = strat;
@askmike
Copy link
Owner

askmike commented Jan 31, 2018

Hey! Thanks for the detailed error report.

Note that both TAlib and Tulip are both external projects.

Few small questions so we can investigate it further:

  • Can you fix the uploaded images so we can see what you mean?
  • Can you provide more information on the exact dataset you ran this over? Gekko calculates candles based on the time you start Gekko, not on specific intervals (if you ran it hourly there is no guarantee that the candles start at specific hours) also please let us know the candle size.

@s5m4
Copy link
Author

s5m4 commented Jan 31, 2018

hi mike, thanks for the fast reply. The images are fixed now.
The dataset I used to produce above results
bitfinex EUR IOT From: 2018-01-27 16:00 To: 2018-01-29-10:30
(reduced range taken from a larger data-set:
bitfinex EUR IOT From: 2018-01-09 16:57 To: 2018-01-29 10:36)
5 Minute Candles

@s5m4
Copy link
Author

s5m4 commented Jan 31, 2018

I once programmed the MFI myself for another node-project and I'm aware of javascript rounding issues with long number types (I'm not coder enough to fully understand them but I'm aware of them ;) ) when I compared the results of my own implementation with the exchange, results were off by values of 1 - 2 at most which I found annoying but ok.. but here the values seem much(!) further off, at some points they seem to have nothing to do with the expected result, not even remotely. The reason why I relied on talib and tulip indicators this time is because I am not confident enough to implement my own gekko-indicator (yet).

@askmike
Copy link
Owner

askmike commented Jan 31, 2018

I will have a look asap at the data being passed around to see whether it might be Gekko instead of these underlying libraries. This will take a few days at least unfortunately (anyone else is free to look at this as well in the mean time).

@askmike askmike added the bug label Jan 31, 2018
@s5m4
Copy link
Author

s5m4 commented Feb 1, 2018

I wrote my own MFI indicator for gekko which I'd like to share.

MFI.zip

I'm having it running along with the tulip MFI indicator atm and so far results match 100%. both are still off from the exchange results but it's hard to really know why, because gekko calculates its own "uneven" candle times like 7:18, 7:23, 7:28 etc.

Is there any way to synchronize the start of gekko with the exchange? (I know it's doable in backtesting, but then again, in backtesting the indicator results seem to be off because of the speed that gekko handles candle data - I read some issues on that, have to read more to be sure)

@mauroprojetos
Copy link

@s5m4 Can friend give you some example to use your indicator?

@rumrush
Copy link

rumrush commented Feb 5, 2018

@s5m4 I've noticed the same issue with the MACD indicator, if you make a strategy with a Talib MACD, a Tulip MACD and a Gekko MACD you'll notice that each results are different.

Also for your issue with uneven time like 1:18, 1:23... have you tried changing the range of your data to start at an "even" number like 1:20 ? Because I think Gekko simply start at the start date and then add the interval to it.

@bvanhou
Copy link

bvanhou commented Aug 2, 2018

Any updates? MFI is horribly off when using the cli. I have been messing with the historysize and binance rest configuration, however no luck at all.

@askmike do you have any theories?

@bvanhou
Copy link

bvanhou commented Aug 9, 2018

I have tried with multiple exchanges and various MFI algorithms, various history sizes and tried on multiple candle start times. Unfortunately, I am still unable to narrow this down. I am up to date on the development branch

My most recent test was on the 1 min candle. However, I usually test on 5min and 1 hr.

Coin: BTC
Market: USDT
Candle Size: 1min
Exchange: Poloniex
TradingView & Coingy : MFI -> 92
Bot: MFI -> 67

screen shot 2018-08-09 at 12 27 26 pm

@askmike
Copy link
Owner

askmike commented Aug 10, 2018

Note that candles are generated differently (for 5min and up) since Gekko doesn't clamp down the 5 minute intervals on the clock (like 12:00 and 12:05, if the first candle is from 12:01 the next one will be 12:06).

Besides from that, a good starting point would be comparing the candle props (OHCL) from Gekko with those from other platforms. Would you be able to let me know if you spot major differences?

Note that small discrepancies for bitfinex are expected, see #2354 (comment) (not related to you, but OP's).

@bvanhou
Copy link

bvanhou commented Aug 12, 2018

@askmike So what I have figured out, is that the async set up of the 3rd party indicators (so far only MFI) seem to mess things up. If I use my internal MFI (by itself) everything seems to work smoothy. However, if I use a tulip Indicator with my internal MFI both mess up or if I just use the tulipIndicator

@stale
Copy link

stale bot commented Oct 24, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you feel this is very a important issue please reach out the maintainer of this project directly via e-mail: gekko at mvr dot me.

@stale stale bot added the wontfix label Oct 24, 2018
@stale stale bot closed this as completed Nov 2, 2018
@jackerlo
Copy link

jackerlo commented Feb 4, 2019

Im using tulip ema and still haven't found a way around to match with tradingview, as i believe its buying and on places it really shouldn't. any solutions? . I'm just following basic tutorial by askmiketuts and trying to view it visually on trading view chart. it buys at place where it really shouldn't be intersecting.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants