Skip to content

Commit 887f185

Browse files
committed
Update MultiMA_TSL.py
1 parent 316212f commit 887f185

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

user_data/strategies/MultiMA_TSL.py

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import talib.abstract as ta
44
from freqtrade.strategy.interface import IStrategy
55
from freqtrade.strategy import (merge_informative_pair,
6-
DecimalParameter, IntParameter, CategoricalParameter, stoploss_from_open)
6+
DecimalParameter, IntParameter, CategoricalParameter)
77
from pandas import DataFrame
88
from functools import reduce
99
from freqtrade.persistence import Trade
@@ -105,40 +105,23 @@ class MultiMA_TSL(IStrategy):
105105
# Number of candles the strategy requires before producing valid signals
106106
startup_candle_count: int = 300
107107

108-
# trailing stoploss hyperopt parameters
109-
# hard stoploss profit
110-
pHSL = DecimalParameter(-0.200, -0.040, default=-0.15, decimals=3, space='sell', optimize=False, load=True)
111-
# profit threshold 1, trigger point, SL_1 is used
112-
pPF_1 = DecimalParameter(0.008, 0.020, default=0.018, decimals=3, space='sell', optimize=False, load=True)
113-
pSL_1 = DecimalParameter(0.008, 0.020, default=0.013, decimals=3, space='sell', optimize=False, load=True)
114-
115-
# profit threshold 2, SL_2 is used
116-
pPF_2 = DecimalParameter(0.040, 0.100, default=0.080, decimals=3, space='sell', optimize=False, load=True)
117-
pSL_2 = DecimalParameter(0.020, 0.070, default=0.040, decimals=3, space='sell', optimize=False, load=True)
118-
119-
# Custom Trailing Stoploss by Perkmeister
120108
def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,
121109
current_rate: float, current_profit: float, **kwargs) -> float:
122110

123-
# hard stoploss profit
124-
HSL = self.pHSL.value
125-
PF_1 = self.pPF_1.value
126-
SL_1 = self.pSL_1.value
127-
PF_2 = self.pPF_2.value
128-
SL_2 = self.pSL_2.value
129-
130-
# For profits between PF_1 and PF_2 the stoploss (sl_profit) used is linearly interpolated
131-
# between the values of SL_1 and SL_2. For all profits above PL_2 the sl_profit value
132-
# rises linearly with current profit, for profits below PF_1 the hard stoploss profit is used.
133-
134-
if (current_profit > PF_2):
135-
sl_profit = SL_2 + (current_profit - PF_2)
136-
elif (current_profit > PF_1):
137-
sl_profit = SL_1 + ((current_profit - PF_1)*(SL_2 - SL_1)/(PF_2 - PF_1))
138-
else:
139-
sl_profit = HSL
140-
141-
return stoploss_from_open(sl_profit, current_profit)
111+
if (current_profit > 0.3):
112+
return 0.05
113+
elif (current_profit > 0.2):
114+
return 0.04
115+
elif (current_profit > 0.1):
116+
return 0.03
117+
elif (current_profit > 0.06):
118+
return 0.02
119+
elif (current_profit > 0.03):
120+
return 0.01
121+
elif (current_profit > 0.018):
122+
return 0.005
123+
124+
return 0.99
142125

143126
def get_ticker_indicator(self):
144127
return int(self.timeframe[:-1])
@@ -177,7 +160,7 @@ def confirm_trade_exit(self, pair: str, trade: Trade, order_type: str, amount: f
177160
current_time: datetime, **kwargs) -> bool:
178161

179162
current_profit = trade.calc_profit_ratio(rate)
180-
if (sell_reason.startswith('sell signal ') and (current_profit > self.pPF_1.value)):
163+
if (sell_reason.startswith('sell signal (') and (current_profit > 0.018)):
181164
# Reject sell signal when trailing stoplosses
182165
return False
183166
return True

0 commit comments

Comments
 (0)