From e5840abaf9f77ecb47df29ca352f07ec0e4ae032 Mon Sep 17 00:00:00 2001 From: hoeckxer Date: Thu, 31 Dec 2020 21:05:47 +0100 Subject: [PATCH 1/3] Added imports to documentation for clarification when using custom stoploss Signed-off-by: hoeckxer --- docs/strategy-advanced.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/strategy-advanced.md b/docs/strategy-advanced.md index 519a9ac62..7876106be 100644 --- a/docs/strategy-advanced.md +++ b/docs/strategy-advanced.md @@ -23,6 +23,10 @@ E.g. `current_profit = 0.05` (5% profit) - stoploss returns `0.02` - then you "l To simulate a regular trailing stoploss of 4% (trailing 4% behind the maximum reached price) you would use the following very simple method: ``` python +# additional imports required +from freqtrade.persistence import Trade +from datetime import datetime + use_custom_stoploss = True def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, From 67ced6a53c78a291c31b62e551cb961449b6ea83 Mon Sep 17 00:00:00 2001 From: Erwin Hoeckx Date: Fri, 1 Jan 2021 20:49:04 +0100 Subject: [PATCH 2/3] Update docs/strategy-advanced.md Co-authored-by: Matthias --- docs/strategy-advanced.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/strategy-advanced.md b/docs/strategy-advanced.md index 7876106be..ab94be1c4 100644 --- a/docs/strategy-advanced.md +++ b/docs/strategy-advanced.md @@ -29,7 +29,7 @@ from datetime import datetime use_custom_stoploss = True - def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, + def custom_stoploss(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float, current_profit: float, **kwargs) -> float: """ Custom stoploss logic, returning the new distance relative to current_rate (as ratio). From 11f36fbaee6d72580cc649635f71ee635c45af8c Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 2 Jan 2021 09:14:31 +0100 Subject: [PATCH 3/3] Fix all custom stoploss samples --- docs/strategy-advanced.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/strategy-advanced.md b/docs/strategy-advanced.md index ab94be1c4..b1fcb50fc 100644 --- a/docs/strategy-advanced.md +++ b/docs/strategy-advanced.md @@ -24,8 +24,12 @@ To simulate a regular trailing stoploss of 4% (trailing 4% behind the maximum re ``` python # additional imports required -from freqtrade.persistence import Trade from datetime import datetime +from freqtrade.persistence import Trade + +class AwesomeStrategy(IStrategy): + + # ... populate_* methods use_custom_stoploss = True @@ -70,6 +74,13 @@ Of course, many more things are possible, and all examples can be combined at wi Use the initial stoploss for the first 60 minutes, after this change to 10% trailing stoploss, and after 2 hours (120 minutes) we use a 5% trailing stoploss. ``` python +from datetime import datetime, timedelta +from freqtrade.persistence import Trade + +class AwesomeStrategy(IStrategy): + + # ... populate_* methods + use_custom_stoploss = True def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, @@ -89,6 +100,13 @@ Use a different stoploss depending on the pair. In this example, we'll trail the highest price with 10% trailing stoploss for `ETH/BTC` and `XRP/BTC`, with 5% trailing stoploss for `LTC/BTC` and with 15% for all other pairs. ``` python +from datetime import datetime +from freqtrade.persistence import Trade + +class AwesomeStrategy(IStrategy): + + # ... populate_* methods + use_custom_stoploss = True def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, @@ -111,6 +129,13 @@ The below example sets absolute profit levels based on the current profit. * Once profit is > 20% - stoploss will be set to 7%. ``` python +from datetime import datetime +from freqtrade.persistence import Trade + +class AwesomeStrategy(IStrategy): + + # ... populate_* methods + use_custom_stoploss = True def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,