zenbot icon indicating copy to clipboard operation
zenbot copied to clipboard

Bot trades with loss all the time.

Open ghost opened this issue 9 years ago • 70 comments

Gave this a try, exchange poloniex, default settings, live trading (not sim).

The bot consistently without exception buys at price X and sells at a lower price. It is doing the opposite of what it should be doing. ( I am not kidding, every trade was with a loss, even in this crazy bull market we have now)

Even tried disabling c.sell_stop_pct = 0 but still it persists in doing this.

Example: Buy NXT at 0.00003540 at 2017-05-24 02:13:05 Sell NXT at 0.00003449 at 2017-05-24 13:02:01

I will leave it running and keep up with the updates if the behavior changes maybe.

Edit: To also mention, I have it running on 10 pairs. Every trade that happened on any of the pairs was this way. Sold at a lower price. And it is running now for about 5 days. Maybe the long term result will be different.

ghost avatar May 25 '17 09:05 ghost

I'm sorry you experienced some rough trades. It appears that (using GMT timezone?) it bought on the first big green candle here and sold on the first big red one:

screen shot 2017-05-25 at 2 29 28 am

That's a whipsaw, a bad signal followed by a corrective signal. At least the sell saved you from holding during the down period at the end there. All trading systems will have bad signals like this and there's no great way to filter them all out. The default strategy tries to filter them with a std. deviation (--neutral_rate=auto) and you can tweak that parameter to set a hard threshold for trend detection.

If you haven't run sims, I'd really recommend doing so... the default settings are a rough starting point. Some altcoins that have 20-50% change per day, it's very risky to trade, manually or with a bot. I would focus on low volatility markets with strong uptrends, and avoid trading on downtrends.

Also the graph could've easily gone the other way and the first buy would've returned profit, but there's no way to code a strategy that can predict the future :) I'm very open to ideas about improving the strategy. The higher the volatility the higher chance for bad signals I think.

carlos8f avatar May 25 '17 10:05 carlos8f

Thanks for the reply. I was already testing zenbot3 and I got kinda used to it. Still trying to grasp this one.

But is it normal behavior that it sells at a lower price if the c.sell_stop_pct is set to 0 (disabled)?

And how far does the bots memory go between restarts? Is it aware of a trade it did three days ago if I restarted it twice in the meantime? If he does not know he bought something at a certain price it would explain the selling at a lower price. (but with the NXT example there were no restarts).

Strategy wise I am just playing around for now. For now I am trying to achieve that the bot buys, if price goes higher sell (80%), if it goes lower dont sell. I have the spend percentage set to 30% on the buy side and 80% on the sell side. So I always hold some coins on both sides. This actually saved me through this, if I gave it 99% the loses would be much higher.

Performance wise it works great btw if you dont count poloniex having issues all the time...

Edit: And no need to be sorry, we all read the disclaimer, use at your own risk :)

Edit2: Would setting this c.max_sell_loss_pct to 0 prevent it from selling at a loss?

ghost avatar May 25 '17 12:05 ghost

how far does the bots memory go between restarts?

the profit figure is the only thing that's carried over (if the balance is the same as the end of last session), it starts fresh with the my_trades, since the gap between stopping and starting the bot could cause unwanted stops to trigger.

Would setting this c.max_sell_loss_pct to 0 prevent it from selling at a loss?

No, that one is meant to be protection in case the price slips in a huge way during order execution, (and it actually holds despite sell signal) if the order takes too long or the exchange has maintenance (prices sometimes do wild stuff after maintenance). setting it to 0 disables that protection, but setting it to 0.1 would keep holding if any loss from last buy. That's dangerous because holding during a downtrend loses profit. If you set --stop_loss_pct you can prevent holding during downtrends, but that's dangerous also since setting it too close to the usual price variation will sell at a loss often.

carlos8f avatar May 26 '17 03:05 carlos8f

I have same case. I lose my btc anytime even if my result of sim is good. sold at lower price and bought at higher price

nao0811ta avatar May 27 '17 00:05 nao0811ta

@nao0811ta Still the same for me too, have a few more days of data now.

Example ETC: Buy 0.00797516 2017-05-25 10:00:39 Sell 0.00656001 2017-05-26 07:00:40 Buy 0.00720500 2017-05-26 13:00:30 Buy 0.07610011 2017-05-26 13:00:48 Sell 0.00654845 2017-05-26 19:00:35 Buy 0.00669999 2017-05-27 16:00:23

At this pattern I assume it will sell again around 0.0062 :smile:

Pulled the code updates now and restarted all the bots. Also set c.max_sell_loss_pct to 0.1 like suggested by @carlos8f to prevent it from selling at a loss. Will report in a few days what happens.

ghost avatar May 28 '17 09:05 ghost

It seems my results are kinda the same as well. This is live trading on gdax.ETH-BTC with --period=5m --trend_ema=15 --max_sell_loss_pct=10. Simulations seemed fine so I decided to give it a shot.

It seems to be consistently selling low, buying high, unless I'm missing something.

2017-05-29 01:31:00: SOLD		at	0.07779 BTC
2017-05-29 01:47:02: BOUGHT		at	0.07830 BTC
2017-05-29 02:53:10: SOLD		at	0.07819 BTC
2017-05-29 03:56:09: BOUGHT		at	0.07819 BTC
2017-05-29 04:40:58: SOLD		at	0.07761 BTC
2017-05-29 04:42:04: SOLD		at	0.07768 BTC
2017-05-29 05:07:51: BOUGHT		at	0.07769 BTC
2017-05-29 05:11:13: SOLD		at	0.07767 BTC
2017-05-29 05:48:20: BOUGHT		at	0.07793 BTC
2017-05-29 05:53:17: SOLD		at	0.07793 BTC
2017-05-29 05:55:29: BOUGHT		at	0.07800 BTC
2017-05-29 06:11:51: SOLD		at	0.07777 BTC
2017-05-29 08:05:50: BOUGHT		at	0.07779 BTC
2017-05-29 08:09:20: BOUGHT		at	0.07774 BTC
2017-05-29 09:23:03: SOLD		at	0.07797 BTC
2017-05-29 09:29:01: BOUGHT		at	0.07815 BTC
2017-05-29 09:51:05: BOUGHT		at	0.07847 BTC
2017-05-29 10:20:58: SOLD		at	0.07824 BTC
2017-05-29 10:55:08: BOUGHT		at	0.07861 BTC
2017-05-29 11:31:18: SOLD		at	0.07828 BTC
2017-05-29 11:50:28: BOUGHT		at	0.07892 BTC

I have tried both the default settings which had the same results, as well as the ones pasted above. Both resulted in 6-8% loss after 12 hours.

@carlos8f thank you for all your work on zenbot; this is not criticism or a complaint, just trying to figure out how we can make this better! :) losing is part of the fun ;)

geoah avatar May 29 '17 13:05 geoah

With c.max_sell_loss_pct set to 0.1 I have seen a few positive trades, but still more exceptions than a rule. Plenty of trades where it buys higher and sells lower. Still an improvement, before not a single trade was positive.

@carlos8f Shouldn't it hold no mater what if set to 0.1? Or did I misunderstand?

ghost avatar May 29 '17 17:05 ghost

@carlos8f For improving the strategy, I would suggest:

Looking at the console output, the bot would make a decent profit if would do the exact opposite of what it is doing now, change the buy signals to sells and sell signals to buys:

Current behaviour: 2017-05-28 17:00:00 0.19860200 XRP-USDT -8.4% 3.1m -- -0.6157 0.2109 sell 2017-05-28 18:00:00 0.19300002 XRP-USDT -2.8% 2.76m -- -0.7452 0.2414 sell 2017-05-28 19:00:00 0.20010000 XRP-USDT +3.7% 1.64m - -0.4908 0.2999 sell 2017-05-28 20:00:00 0.19850000 XRP-USDT -0.8% 905.88k -- -0.5093 0.3233 sell 2017-05-28 21:00:00 0.20490000 XRP-USDT +3.2% 872.12k - -0.2863 0.3405 2017-05-28 22:00:00 0.20140000 XRP-USDT -1.7% 822.16k - -0.3742 0.3425 sell 2017-05-28 23:00:00 0.19505002 XRP-USDT -3.2% 598.37k -- -0.5437 0.3380 sell 2017-05-29 00:00:00 0.20362669 XRP-USDT +4.4% 392.32k - -0.2502 0.3496 2017-05-29 01:00:00 0.21900999 XRP-USDT +7.6% 1.05m + 0.2350 0.3450 2017-05-29 02:00:00 0.21626223 XRP-USDT -1.3% 542.16k + 0.1356 0.3317 2017-05-29 03:00:00 0.21255057 XRP-USDT -1.7% 345.17k - 0.0138 0.3182 2017-05-29 04:00:00 0.20899996 XRP-USDT -1.7% 1.13m - -0.0951 0.2854 2017-05-29 05:00:00 0.20708824 XRP-USDT -0.9% 909.19k - -0.1472 0.2745 2017-05-29 06:00:00 0.20500001 XRP-USDT -1.0% 1.88m - -0.2016 0.2683 2017-05-29 07:00:00 0.20298180 XRP-USDT -1.0% 328.84k - -0.2506 0.2647 2017-05-29 08:00:00 0.21083519 XRP-USDT +3.9% 272.5k - 0.0055 0.2613 2017-05-29 09:00:00 0.21099996 XRP-USDT +0.1% 430.08k - 0.0102 0.2535 2017-05-29 10:00:00 0.21199999 XRP-USDT +0.5% 874.55k + 0.0401 0.2219 2017-05-29 11:00:00 0.21140197 XRP-USDT -0.3% 377.85k - 0.0192 0.2126 2017-05-29 12:00:00 0.21881808 XRP-USDT +3.5% 557.72k + 0.2449 0.1949 buy 2017-05-29 13:00:00 0.21950000 XRP-USDT +0.3% 1.51m + 0.2494 0.2069 buy 2017-05-29 14:00:00 0.21700000 XRP-USDT -1.1% 604.79k + 0.1566 0.2052 2017-05-29 15:00:00 0.21959016 XRP-USDT +1.2% 457.42k + 0.2250 0.1621 buy 2017-05-29 16:00:00 0.21481973 XRP-USDT -2.2% 791.3k + 0.0653 0.1541 2017-05-29 17:00:00 0.22300001 XRP-USDT +3.8% 1.08m + 0.3090 0.1471 buy 2017-05-29 18:00:00 0.22691937 XRP-USDT +1.8% 3.37m + 0.4067 0.1608 buy 2017-05-29 19:00:00 0.22797344 XRP-USDT +0.5% 3.19m ++ 0.4106 0.1827 buy 2017-05-29 20:00:00 0.23000000 XRP-USDT +0.9% 1.13m ++ 0.4433 0.1947 buy

Buy when ema value bottoms. On a 1h period for example, track last 12hours. If ema current is negative and smaller then ema n-1 DO NOTHING. If ema current is equal or is getting larger than n-1 then BUY.

Sell when ema tops. If ema current is positive and larger than ema n-1 DO NOTHING. If ema current is equal or getting smaller than ema n-1 SELL.

Of course evening it out a bit, looking at a few hours of ema values back, not just the last one to kinda catch the trend.

What do you think?

ghost avatar May 29 '17 18:05 ghost

@krilson I will try experimenting with that, however I'm a little confused:

  • ema n-1 is this a comparison of 12 periods ago, or 1 period? (how are last 12 hours "tracked"?)
  • Comparing the ema's themselves, or the ema change % from 1 period ago (which is what's displayed)?
  • smaller/getting smaller - do you mean closer to 0/crossed the other way? or further negative?

carlos8f avatar May 30 '17 02:05 carlos8f

Also set c.max_sell_loss_pct to 0.1 like suggested by @carlos8f to prevent it from selling at a loss. @carlos8f Shouldn't it hold no mater what if set to 0.1? Or did I misunderstand?

To be clear I don't recommend that as a setting (yes it should hold, unless you restart the bot in which case the trade memory resets)

carlos8f avatar May 30 '17 02:05 carlos8f

I should also note that

  • even in very profitable simulations, error rate (% that trades were unprofitable) is normally in the 60-70% range.
  • So usually, about 20% of the trades result in 80% of the profit (80-20 rule). When the market is going sideways and lots of whipsaws occur, error rate is usually higher, but once a trend emerges you'll be on the good side.
  • In general the higher the volatility of a market, the quicker the period required. However:
  • On Poloniex the trade fees can hurt during sideways markets especially with quicker period, so running a 10m or 5m period may be much more profitable on a market like GDAX that has no maker fees.

carlos8f avatar May 30 '17 02:05 carlos8f

Live trading with Bitfinex gets similar negative results. Paper trading gives possitive with the same settings.

nedievas avatar May 30 '17 03:05 nedievas

@nedievas interesting. I will try to implement the partial balance patch https://github.com/carlos8f/zenbot/issues/174 , live trade with small amounts and paper trade at the same time, trying to see what's the difference

carlos8f avatar May 30 '17 03:05 carlos8f

hey guys, I posted a readme update for "known issues" relating to losses seen in live trading. I've been busy lately so it may take some time for improvement. Thanks!

https://github.com/carlos8f/zenbot#known-issues-and-current-status

carlos8f avatar May 31 '17 04:05 carlos8f

Hi, I'm not an expert but just thinking out loud here. Would it be nice if the --period goes to, let's say from 30 to 10 minutes as soon as a buy was initiated? In this case the bot sells sooner?

rondijkstra avatar Jun 01 '17 16:06 rondijkstra

@rondijkstra this hold period is one that v3 had, it can end either good or bad.

DeviaVir avatar Jun 01 '17 16:06 DeviaVir

Ok!

rondijkstra avatar Jun 01 '17 16:06 rondijkstra

https://github.com/carlos8f/zenbot/compare/master...infatrus:patch-1?diff=unified&name=patch-1#diff-dbf0823e37d3e5cfe1fb4563f5202d18L96

I know it's stupid, but try to test this with your setting. I've got better results in sim and paper with error rate below 30% (even 0%) - it seems that standard setting gives profit only in specific market conditions.

infatrus avatar Jun 01 '17 17:06 infatrus

I think this is something for @krilson to test. Instead of me, he seems to test very thoroughly. Please confirm, @krilson. Or can we test on --paper mode as well (Because I don't feel like experimenting on the edge with real money)

rondijkstra avatar Jun 01 '17 17:06 rondijkstra

I did some testing (SIM) with DGB that was rising pretty fast yesterday. The sim of standard setting gave me 42.6% profit. The newly strategy, thus with the 'reversed trading', gave me -9.36% :(

(5 day sim gave +103.97% VS 4.52% profit..)

rondijkstra avatar Jun 04 '17 15:06 rondijkstra