askmike / gekko

A bitcoin trading bot written in node - https://gekko.wizb.it/
MIT License
10.07k stars 3.94k forks source link

RSI is wrong on tradebot #759

Closed aneopsy closed 7 years ago

aneopsy commented 7 years ago

calculated RSI properties for candle: 2017-05-27 21:43:06 (DEBUG): rsi: 98.42998966176029

The RSI/TSI has a problem of range on tradebot is 98 to 100 in early. EMA problem ?

Solved: Create a TAlib version of RSI strat

darklow commented 7 years ago

@aneopsy Could you please share your TAlib version of RSI strat? Thanks.

talvasconcelos commented 7 years ago

@darklow Talib doesn't install on windows, if it's your OS. Have the same issue. Don't know about the RSI problem though

askmike commented 7 years ago

If anyone can let me know what is wrong with the RSI version I can fix that :)

andreialecu commented 7 years ago

I have the same problem and there's nothing wrong with the RSI version, the problem is that there is no history being loaded when gekko first starts.

The history setting doesn't seem to work. For example with Bitstamp, it can load up to a day of history, but it doesn't actually make candles out of it.

I've made a quick workaround for it in this commit: https://github.com/andreialecu/gekko/commit/04fa5758bde229009040b95538779e05ac8c0fb4, but I don't think it's the right fix. I need to get more familiar with the code before fixing it properly.

askmike commented 7 years ago

I have the same problem and there's nothing wrong with the RSI version, the problem is that there is no history being loaded when gekko first starts.

When the code hits this path it means that Gekko just called an exchange and it returned all data, which means that as soon as the pipeline starts the same data will be fetched and all data will be fed into the strat. If this did not work for you please open a new issue, because I think your commit will pump the same candles twice into the strat.

andreialecu commented 7 years ago

While that may be true, without that particular hack the rsi always starts at 99+. At least on bitstamp. So the other code path is probably not working for some reason. I'll take another look at it tonight.

jjngpuri commented 7 years ago

I have the same problem with RSI, any updates on this?

talvasconcelos commented 7 years ago

rsi is calculated on live, at least is what I think.

On Wed, Jun 14, 2017, 4:44 AM jjngpuri notifications@github.com wrote:

I have the same problem with RSI, any updates on this?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/askmike/gekko/issues/759#issuecomment-308311460, or mute the thread https://github.com/notifications/unsubscribe-auth/ALhf8gFrsonnG7yD7kmRV6PLOjeJa_RLks5sD1b_gaJpZM4Noc4a .

Yroethiel commented 7 years ago

Same issue here, seems to match up with andreialecu is seeing. I have a full import of Poloniex history for my currency pair (going back months). The trade bot appears to recognise this history exists when it starts, and loads it in. However, when the first trade is triggered, the DEBUG console is giving me a value of 99+ for the RSI (when measuring it separately, I'm getting below 30), which suggests the history isn't being used to calculate the RSI. As such, the bot appears to be "selling low".

Don't appear to get this issue when running backtester in the UI. Is it perhaps because the number of candles being used to generate the initial history can be defined here?

shanehull commented 7 years ago

My RSI strat was selling ridiculously low, too. I figured it was due to a bad strategy so I didn't bother enabling debug. After backtesting this again using the same settings, I find it returns an almost perfect result, with clear buy/sell indicators on the lows and highs. The market I was running it on did not change drastically compared to the history I tested it on.

I'm happy to test this live if anyone needs more info.

score1more4me commented 7 years ago

I created an RSI strategy from the TALib library. When running TALib RSI it in paper trade mode, it is unable to calculate the RSI from stored exchange history. However, it does just fine in backtest mode.

The only real advantage, I can see, from using TALib vs the built-in RSI is that it won't trade on incorrect data. The built-in RSI strategy seems to hover right at 99 to 98, at least for the hours that I let it run. My particular strategy requires a few hours of data to calculate a trend...

Anyway, it seems like there's possibly a glitch with using stored data for these two algos. Here's a debug log.

`2017-07-07 14:31:27 (INFO): Setting up Gekko in realtime mode 2017-07-07 14:31:27 (INFO): 2017-07-07 14:31:27 (INFO): Setting up: 2017-07-07 14:31:27 (INFO): Candle writer 2017-07-07 14:31:27 (INFO): Store candles in a database 2017-07-07 14:31:27 (INFO):

2017-07-07 14:31:27 (INFO): Setting up: 2017-07-07 14:31:27 (INFO): Trading Advisor 2017-07-07 14:31:27 (INFO): Calculate trading advice 2017-07-07 14:31:27 (INFO): Using the strategy: talib-rsi 2017-07-07 14:31:27 (INFO): The trading method requests 600 minutes of historic data. Checking availablity.. 2017-07-07 14:31:27 (INFO):

2017-07-07 14:31:27 (DEBUG): Available local data: 2017-07-07 14:31:27 (DEBUG): from: 600 minutes ago 2017-07-07 14:31:27 (DEBUG): to: 2 minutes ago 2017-07-07 14:31:27 (INFO): Usable local data available, trying to match with exchange data.. 2017-07-07 14:31:27 (DEBUG): Fetching exchange data since 17 minutes ago 2017-07-07 14:31:27 (DEBUG): Scanning back in the history needed... 2017-07-07 14:31:27 (DEBUG): 2017-07-07T21:14:00+00:00 2017-07-07 14:31:27 (DEBUG): Scanning backwards...2017-07-07T21:25:40.359Z 2017-07-07 14:31:27 (DEBUG): Scanning backwards...2017-07-07T21:17:22.717Z 2017-07-07 14:31:28 (DEBUG): Backwards: 2017-07-07T21:06:27.353Z (17817979) to 2017-07-07T21:09:10.026Z (17818078) 2017-07-07 14:31:28 (DEBUG): Backwards: 2017-07-07T21:09:10.026Z (17818079) to 2017-07-07T21:17:22.167Z (17818178) 2017-07-07 14:31:28 (DEBUG): Backwards: 2017-07-07T21:17:22.717Z (17818179) to 2017-07-07T21:25:40.359Z (17818278) 2017-07-07 14:31:29 (DEBUG): Backwards: 2017-07-07T21:25:40.359Z (17818279) to 2017-07-07T21:30:23.864Z (17818378) 2017-07-07 14:31:29 (DEBUG): Backwards: 2017-07-07T21:26:11.713Z (17818285) to 2017-07-07T21:30:57.458Z (17818384) 2017-07-07 14:31:29 (DEBUG): Backwards: 2017-07-07T21:26:11.713Z (17818286) to 2017-07-07T21:30:57.458Z (17818385) 2017-07-07 14:31:29 (DEBUG): Backwards: 2017-07-07T21:26:19.222Z (17818288) to 2017-07-07T21:30:57.458Z (17818387) 2017-07-07 14:31:30 (DEBUG): Backwards: 2017-07-07T21:26:19.222Z (17818288) to 2017-07-07T21:30:57.458Z (17818387) 2017-07-07 14:31:30 (DEBUG): Scan finished: data found:800 2017-07-07 14:31:30 (DEBUG): Available exchange data: 2017-07-07 14:31:30 (DEBUG): from: 25 minutes ago 2017-07-07 14:31:30 (DEBUG): to: 0 minutes ago 2017-07-07 14:31:30 (DEBUG): Stitching datasets 2017-07-07 14:31:30 (INFO): Full history locally available. Seeding the trading method with all required historical candles. 2017-07-07 14:31:30 (DEBUG): Seeding with: 2017-07-07 14:31:30 (DEBUG): from: 600 minutes ago 2017-07-07 14:31:30 (DEBUG): to: 26 minutes ago undefined 2017-07-07 14:31:30 (DEBUG): rsi: undefined undefined 2017-07-07 14:31:30 (DEBUG): rsi: undefined undefined 2017-07-07 14:31:30 (DEBUG): rsi: undefined undefined 2017-07-07 14:31:30 (DEBUG): rsi: undefined undefined 2017-07-07 14:31:30 (DEBUG): rsi: undefined undefined 2017-07-07 14:31:30 (DEBUG): rsi: undefined undefined 2017-07-07 14:31:30 (DEBUG): rsi: undefined undefined 2017-07-07 14:31:30 (DEBUG): rsi: undefined undefined 2017-07-07 14:31:30 (DEBUG): rsi: undefined 2017-07-07 14:31:30 (INFO): Setting up: 2017-07-07 14:31:30 (INFO): Advice logger 2017-07-07 14:31:30 (INFO):
2017-07-07 14:31:30 (INFO): Setting up: 2017-07-07 14:31:30 (INFO): Paper Trader 2017-07-07 14:31:30 (INFO): Paper trader that simulates fake trades. 2017-07-07 14:31:30 (INFO):

2017-07-07 14:31:30 (INFO): Starting to watch the market: GDAX BTC/USD 2017-07-07 14:31:30 (DEBUG): scheduling ticks 2017-07-07 14:31:30 (DEBUG): Requested BTC/USD trade data from GDAX ... 2017-07-07 14:31:30 (DEBUG): Scanning back in the history needed... 2017-07-07 14:31:30 (DEBUG): 2017-07-07T21:14:00+00:00 2017-07-07 14:31:30 (DEBUG): Scanning backwards...2017-07-07T21:26:19.222Z 2017-07-07 14:31:31 (DEBUG): Scanning backwards...2017-07-07T21:17:44.576Z 2017-07-07 14:31:31 (DEBUG): Backwards: 2017-07-07T21:07:12.102Z (17817988) to 2017-07-07T21:10:26.893Z (17818087) 2017-07-07 14:31:31 (DEBUG): Backwards: 2017-07-07T21:10:26.893Z (17818088) to 2017-07-07T21:17:37.105Z (17818187) 2017-07-07 14:31:32 (DEBUG): Backwards: 2017-07-07T21:17:44.576Z (17818188) to 2017-07-07T21:26:11.713Z (17818287) 2017-07-07 14:31:32 (DEBUG): Backwards: 2017-07-07T21:26:19.222Z (17818288) to 2017-07-07T21:30:57.458Z (17818387) 2017-07-07 14:31:33 (DEBUG): Backwards: 2017-07-07T21:26:21.077Z (17818289) to 2017-07-07T21:30:57.458Z (17818388) 2017-07-07 14:31:33 (DEBUG): Backwards: 2017-07-07T21:26:21.077Z (17818289) to 2017-07-07T21:30:57.458Z (17818388) 2017-07-07 14:31:33 (DEBUG): Scan finished: data found:600 2017-07-07 14:31:33 (DEBUG): Processing 600 new trades. From 2017-07-07 21:07:12 UTC to 2017-07-07 21:30:57 UTC. (24 minutes) 2017-07-07 14:31:50 (DEBUG): Requested BTC/USD trade data from GDAX ... 2017-07-07 14:31:50 (DEBUG): Processing 46 new trades. From 2017-07-07 21:30:57 UTC to 2017-07-07 21:31:05 UTC. (a few seconds) 2017-07-07 14:32:10 (DEBUG): Requested BTC/USD trade data from GDAX ... 2017-07-07 14:32:10 (DEBUG): Processing 13 new trades. From 2017-07-07 21:31:28 UTC to 2017-07-07 21:31:59 UTC. (a few seconds) 2017-07-07 14:32:30 (DEBUG): Requested BTC/USD trade data from GDAX ... 2017-07-07 14:32:30 (DEBUG): Processing 4 new trades. From 2017-07-07 21:32:04 UTC to 2017-07-07 21:32:06 UTC. (a few seconds) undefined 2017-07-07 14:32:30 (DEBUG): rsi: undefined 2017-07-07 14:32:50 (DEBUG): Requested BTC/USD trade data from GDAX ... 2017-07-07 14:32:50 (DEBUG): No new trades.

snip 2017-07-07 17:52:02 (DEBUG): Processing 9 new trades. From 2017-07-08 00:51:45 UTC to 2017-07-08 00:52:01 UTC. (a few seconds) 37.24163848177364 37.24163848177364 2017-07-07 17:52:02 (DEBUG): In low since 1 candle(s)`

wuhkuh commented 7 years ago

Sources online use the ~cumulative moving average (CMA)~ n-period smoothed or modified moving average (SMMA) over a period of 14 days, where Gekko uses EMA as average for RSI. Could this be an issue?

askmike commented 7 years ago

Let's ping @cykedev, he added RSI back in 2014 (#208)

EDIT: this seems to be related:

Note: as EMA is used to calculate the average gains and losses, you should use at least 50-100 candles before starting to trade or you might get wrong values.

wuhkuh commented 7 years ago

I'm working on a TA library as well, so I might be able to port the calculations in the near future, if @cykedev doesn't respond. A possible problem would be which RSI to pick; the original one from the paper or a newer version, for example the ones mentioned on Wikipedia. This choice is up to you, of course.

askmike commented 7 years ago

@wuhkuh I came across this, maybe you can use it in a way? https://github.com/WaiSiuKei/ta-lib

askmike commented 7 years ago

New version of RSI has landed in develop branch, props to @wuhkuh! As soon as that lands in a release I will consider this issue closed :)

askmike commented 7 years ago

That landed in stable a while ago!