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

Fixing Trailing Stop Loss to correctly update the stop_loss value #193

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

abradner
Copy link

What are you addressing in this PR

Place X in the slot...

  • Functionality
  • Ease of use
  • Bug fix

How have you tested this PR

Corrected behaviour has been verified, see below

In your own words, please share how this makes the codebase better.

when USE_TRAILING_STOP_LOSS is enabled and the take_profit value for a coin is reached the new stop_loss value should be set to just below the existing take_profit (ie take_profit - TRAILING_STOP_LOSS).

Due to the order of the operations this was being incorrectly set to take_profit + TRAILING_TAKE_PROFT - TRAILING_STOP_LOSS

This PR simply switches the order of the operations to update take_profit and stop_loss to prevent the bug.

Test output

$ python3 Binance\ Detect\ Moonings.py --debug
[2021-06-15 14:14:35] loaded config below
{
    "script_options": {
        "TEST_MODE": false,
<snip>
    "trading_options": {
<snip>
        "TAKE_PROFIT": 0.5,
        "USE_TRAILING_STOP_LOSS": true,
        "TRAILING_STOP_LOSS": 0.05,
        "TRAILING_TAKE_PROFIT": 0.75,
        "TRADING_FEE": 0.075,
<snip>
[2021-06-15 14:45:28] PERLUSDT TP reached, adjusting TP 1.49  and SL 0.45 accordingly to lock-in profit

For comparison, existing incorrect behaviour with same params:

[2021-06-15 14:02:54] ATAUSDT TP reached, adjusting TP 1.36  and SL 1.31 accordingly to lock-in profit
[2021-06-15 14:03:04] TP or SL reached, selling 15 ATAUSDT - 0.95917 - 0.96757 : 0.73% Est:$0.11

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

Successfully merging this pull request may close these issues.

1 participant