Allow Strategy subclassing in different files by enabling local imports

This commit is contained in:
Matthias
2022-03-20 13:07:06 +01:00
parent fcec071a08
commit 49e087df5b
3 changed files with 45 additions and 24 deletions

View File

@@ -164,16 +164,15 @@ class MyAwesomeStrategy2(MyAwesomeStrategy):
Both attributes and methods may be overridden, altering behavior of the original strategy in a way you need.
!!! Note "Parent-strategy in different files"
If you have the parent-strategy in a different file, you'll need to add the following to the top of your "child"-file to ensure proper loading, otherwise freqtrade may not be able to load the parent strategy correctly.
If you have the parent-strategy in a different file, you can still import the strategy.
Assuming `myawesomestrategy.py` is the filename, and `MyAwesomeStrategy` the strategy you need to import:
``` python
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parent))
from myawesomestrategy import MyAwesomeStrategy
```
This is the recommended way to derive strategies to avoid problems with hyperopt parameter files.
## Embedding Strategies
Freqtrade provides you with an easy way to embed the strategy into your configuration file.