zenbot icon indicating copy to clipboard operation
zenbot copied to clipboard

First in last out for buy and sell order

Open stinkyjames opened this issue 8 years ago • 5 comments

System information

  • Have I written custom code (as opposed to using zenbot vanilla): I can understand and modify basic codes, like change the output from "vs. buy hold" to "bot vs. buy hold"

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Distributor ID: Ubuntu Description: Ubuntu 16.04.3 LTS Release: 16.04 Codename: xenial

  • Zenbot version (commit ref, or version): current master

  • Zenbot branch: master

  • NodeJS version: v8.9.4

  • Python version (when using a python script): not using python script

  • Exact command to reproduce (include everything): NA

  • Did I make any changes to conf-sample.js?: I changed the conf.js to my desired settings

Describe the problem

I have made changes to the engine.js file to enable it to make multiple buys without waiting for a sell to happen by reducing "held_pct" to 0.

When the sell side is triggered, it only looks at the last buy price instead of performing a first-in last-out of the buy prices. I'm guessing a counter needs to be added to the buy price for the sell price to reference, such as buy_price_1, and buy_price_2, and buy_price_3.. or buy_price_x where x is incremented for each buy and when it triggers a sell it will look at the most recent buy_price_x , for example buy_price_3, and makes sure to reference buy_price_3, and then nulls buy_price_3 and moves on to the buy_price_2 if another sell is triggered to sell by referencing buy price_2. It correctly works with the last buy price but I would like it to work for all the previous buys until only the first buy is left to be referenced as the last buy price.

basically the scenario will play out as follows:

first buy trigger: buy_price_1

sell trigger sell references buy_price_1

buy trigger: buy_price_1

buy trigger: buy_price_1 exist create buy_price_2

sell trigger sell references buy_price_2 nulled/deletes buy_price_2

buy trigger: buy_price_1 exist create buy_price_2

buy trigger: buy_price_1 exist buy_price_2 exist create buy_price_3

sell trigger sell references buy_price_3 nulled/deletes buy_price_3

sell trigger sell references buy_price_2 nulled/deletes buy_price_2

buy trigger: buy_price_1 exist create buy_price_2

sell trigger sell references buy_price_2 nulled/deletes buy_price_2

sell trigger sell references buy_price_1

sell trigger sell references buy_price_1

That's in. First-in Last-out for buy_price when a sell triggered.

Source code / Error logs

Feature request

stinkyjames avatar Mar 04 '18 16:03 stinkyjames

I suppose this is in reference to #1389

held_pct was added in b0b7c9205e5ca587aacbe80bb5c3d76108664a84 which unfortunately doesn't outline why it was added in the first place.

Now considering held_pct blocks the bot from doing consecutive buys i'd say we should look into figuring out why and simply fix just that.

Regarding this report, will i get the idea behind FILO i don't see how this is supposed to help improve the bots buy/sell habit as we absolutely do want to always use the last buy/sell price for loss protection.

Lets assume the bot does a buy - sell - sell - buy - sell we want to use the first buy price during the first and second sell, followed by the second sell price during the second buy and finally the second buy price during the third sell to trigger buy/sell loss.

defkev avatar Mar 04 '18 20:03 defkev

After thinking about this the idea isn't to bad at all.

Assuming the previous example using buy - sell - sell - buy - sell the bot would make a possible loss on the second buy signal if the second sell price was above the first.

sell low ... sell high, buy low = loss
sell high ... sell low, buy low = win

Will we currently ensure the buy price is below the last sell price it could still be (way) above the first sell price, causing a loss.

Same for a sell on two (or more) previous consecutive buys if the last buy price is below the previous.

buy high ... buy low, sell high = loss
buy low ... buy high, sell high = win

Without looking into it i suppose held_pct is supposed to prevent just that, only for buy signals of course, as we don't have any such "protection" for sells right now. Which would also explain why the bot refuses to do consecutive buys but not sells.

I'll look into it once if get the chance.

defkev avatar Mar 05 '18 02:03 defkev

If you're able to implement a FILO on referencing the buy_price when it makes a sell, every sell will be higher than it's buy in price if sell_loss protection is enabled. I was looking into stack, but can't figure out how to make it happen.

stinkyjames avatar Mar 05 '18 02:03 stinkyjames

Frankly this shouldn't be to hard to implement if we simplify it by always aiming for a profit, no matter what.

defkev avatar Mar 05 '18 02:03 defkev

Let's do it. :)

stinkyjames avatar Mar 05 '18 02:03 stinkyjames