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

Feature: Proceed exit while having open order, for backtesting and live #10062

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

Axel-CH
Copy link
Contributor

@Axel-CH Axel-CH commented Apr 10, 2024

Summary

Solve the issue: #9760

Quick changelog

  • Create Unit tests reproducing meaningful Backtests Scenarios
  • Create Unit tests reproducing meaningful Live Scenarios
  • Update Backtest to fix newly created tests
  • Update Freatradebot to fix newly created tests

What's new?

This PR aim to allow trade to exit properly while having open order, on backtest and live

assert trade

print(f'trade.liquidation_price: {trade.liquidation_price}')
# TODO QUESTION Why leverage stay at 1.0 ?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xmatthias could you provide me the proper way to edit leverage and stoploss in order to create the test scenario properly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your test runs on spot markets (the default for default_conf).
Futures markets are "opt in" ... so you need to re-set trading_mode to futures for leverage to not be ignored.

I'd also use default_conf_usdt for new tests ... doing tests with BTC feels a bit awkward if you consider it's volatility (most older tests assume a price of 10-15k - which nowadays seems odd) - i always found that to help with trying to do the calculations manually to ensure the test actually makes sense.

@Axel-CH Axel-CH self-assigned this Apr 10, 2024
@Axel-CH Axel-CH marked this pull request as draft April 10, 2024 23:30
@Axel-CH Axel-CH changed the title wip: add backtesting tests related to exist while having open orders Feature: Proceed exit while having open order, for backtesting and live Apr 10, 2024
@xmatthias xmatthias added WIP Work in progress, do not merge for now Enhancement Enhancements to the bot. Get lower priority than bugs by default. labels Apr 11, 2024
# TODO This should FAIL curently as exits is not triggered if trade.has_open_orders
assert res
assert res.exit_reason == ExitType.STOP_LOSS.value
assert sl_order.status == 'closed' # TODO why the stoploss order is not filled ?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xmatthias I must validate that the SL order is properly filled when there is no open entry or exit order, but the SL order is not filled in that case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your approach is a bit off if i'm honest.

you're calling backtesting internals (_check_trade_exit() is not supposed to close the order) - but expect things that happen in other parts of backtesting to also happen.
You CAN make these happen - but it'll not happen automatically if you call partials.

The above called method is just checking, and eventually creating an order.
Handling of the actual order handles after this call - directly in backtest_loop().
That'll handle both orders that were created in this iteration - as well as orders that are there from previous candles and didn't fill yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thank you for the clarification

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So from what I understand I must do a test strategy that is closer to "test_backtest_one" using "UNITTEST_BTC" data, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"probably" yes ...

@Axel-CH Axel-CH force-pushed the feature/proceed-exit-while-open-order branch from 9dd125f to 7dd5648 Compare April 14, 2024 04:17
@coveralls
Copy link

coveralls commented Apr 14, 2024

Coverage Status

coverage: 94.619% (+0.002%) from 94.617%
when pulling faeda2a on Axel-CH:feature/proceed-exit-while-open-order
into 65654a4 on freqtrade:develop.

@Axel-CH Axel-CH force-pushed the feature/proceed-exit-while-open-order branch from 7dd5648 to faeda2a Compare April 14, 2024 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Enhancements to the bot. Get lower priority than bugs by default. WIP Work in progress, do not merge for now
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants