Skip to content
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

Proper Implementation of Windowed % Increase Checking #66

Closed
Davidobot opened this issue May 13, 2021 · 5 comments
Closed

Proper Implementation of Windowed % Increase Checking #66

Davidobot opened this issue May 13, 2021 · 5 comments

Comments

@Davidobot
Copy link
Contributor

The current code for checking for X% increase (or Z% decrease) over a Y amount of time doesn't make too much sense as it only checks at the bounds, ie it can miss increases that happen during this time period.

I'll implement this when I have the time, but basically:

keep a circular queue Q of length Y * M (eg Y in minutes, M is how many times a minute to sample the prices)
M times a minute: 
    add the current price to Q, pushing the oldest price if necessary

    lowest_price, cor_low_index = min(Q) # lowest price in Y minute window with corresponding index
    highest_price, cor_high_index = max(Q) # highest price in Y minute window with corresponding index

    # index check makes sure price is going up not down
    if ((highest_price - lowest_price) / lowest_price) * 100 >= X and cor_high_index > cor_low_index:
        # BUY coin; hit increase condition
    elif ((highest_price - lowest_price) / lowest_price) * 100 >= Z and cor_high_index < cor_low_index:
        # SELL coin as SL hit

and similarly for TP and whatnot.

This ensures that if the price goes up, say, 5% in 3 minutes rather than in 5 minutes then the bot will still jump on board. This also makes sure that you sell as soon as your SL is hit and not (in the worst case) 5 minutes afterwards when it had the chance to drop even more.

The windowed idea is great for detecting "spikes" but it just needs a bit more algorithmic massaging to get it to be correctly implemented. This more frequent checking is absolutely essential for SL though. I would set M=60 checks/min ie 1 a second. Y = 5 minutes works well.

This is a better approach than what is suggested in #65 (ie to decrease check time to seconds)

@ShogunMan
Copy link
Collaborator

Agree that this is the correct approach. My change from minutes to seconds was to allow for more granularity in specifying timeframes.

@ShogunMan
Copy link
Collaborator

I think my change to more frequent checks with the RECHECK_INTERVAL actually does this.

@Davidobot
Copy link
Contributor Author

I think my change to more frequent checks with the RECHECK_INTERVAL actually does this.

I think so, but only for SL/TP, not for initially buying into the coin.

@ShogunMan
Copy link
Collaborator

Thats true, a rolling window for initial buying should be implemented.

@Davidobot
Copy link
Contributor Author

There we go :)

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

No branches or pull requests

2 participants