Timeframe
1h
Direction
Long Only
Stoploss
-99.0%
Trailing Stop
Yes
ROI
0m: 10.0%
Interface Version
N/A
Startup Candles
30
Indicators
0
freqtrade/freqtrade-strategies
freqtrade/freqtrade-strategies
freqtrade/freqtrade-strategies
this is an example class, implementing a PSAR based trailing stop loss you are supposed to take the `custom_stoploss()` and `populate_indicators()` parts and adapt it to your own strategy
freqtrade/freqtrade-strategies
from freqtrade.strategy.interface import IStrategy
from pandas import DataFrame
class SingleAssetStrategy(IStrategy):
timeframe = '1h'
startup_candle_count = 30
stoploss = -0.99
trailing_stop = True
use_custom_stoploss = True
use_exit_signal = False
use_custom_exit = False
minimal_roi = {"0": 0.1}
process_only_new_candles = True
def populate_indicators(self, df: DataFrame, metadata: dict) -> DataFrame:
df['20_high'] = df['high'].rolling(20).max()
df['20_low'] = df['low'].rolling(20).min()
df['3_low'] = df['low'].rolling(3).min()
return df
def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
df.loc[
(df['close'] > df['20_high'].shift(1)),
'enter_long'
] = 1
df.loc[
(df['close'] < df['20_low'].shift(1)),
'enter_short'
] = 1
return df
def custom_stoploss(self, pair, trade, current_time, current_rate, current_profit, **kwargs):
df = self.dp.get_analyzed_dataframe(pair, self.timeframe)
if df is None or len(df) < 3:
return 1
try:
idx = df.index.get_loc(trade.open_date_utc, method='nearest')
# trailing_low = df['3_low'].iloc[idx]
trailing_low = df['3_low'].iloc[-1]
if current_rate < trailing_low:
return 0.01
except Exception:
pass
return 1
def confirm_trade_entry(self, *args, **kwargs) -> bool:
return len(self.wallets.get_all_open_trades()) == 0
def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
df['exit_long'] = 0
df['exit_short'] = 0
return df