Timeframe
1h
Direction
Long Only
Stoploss
-10.0%
Trailing Stop
No
ROI
0m: 6.0%, 120m: 10.0%, 240m: 20.0%
Interface Version
3
Startup Candles
N/A
Indicators
3
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
Strategy 003 author@: Gerald Lonlas github@: https://github.com/freqtrade/freqtrade-strategies
from datetime import datetime
import numpy as np # noqa
import pandas as pd # noqa
from pandas import DataFrame
from technical.indicators import ichimoku
# --------------------------------
# Add your lib to import here
import freqtrade.vendor.qtpylib.indicators as qtpylib
from freqtrade.persistence import Trade
from freqtrade.strategy import (IStrategy)
class MyIchimoku2(IStrategy):
"""
"""
# Strategy interface version - allow new iterations of the strategy interface.
# Check the documentation or the Sample strategy to get the latest version.
INTERFACE_VERSION = 3
# Can this strategy go short?
can_short: bool = False
# Minimal ROI designed for the strategy.
# This attribute will be overridden if the config file contains "minimal_roi".
minimal_roi = {
"240": 0.2,
"120": 0.1,
"0": 0.06,
}
# "minimal_roi": {
# "40": 0.0, # Exit after 40 minutes if the profit is not negative
# "30": 0.01, # Exit after 30 minutes if there is at least 1% profit
# "20": 0.02, # Exit after 20 minutes if there is at least 2% profit
# "0": 0.04 # Exit immediately if there is at least 4% profit
# },
stoploss = -0.10
use_custom_stoploss = True
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).
e.g. returning -0.05 would create a stoploss 5% below current_rate.
The custom stoploss can never be below self.stoploss, which serves as a hard maximum loss.
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
When not implemented by a strategy, returns the initial stoploss value
Only called when use_custom_stoploss is set to True.
:param pair: Pair that's currently analyzed
:param trade: trade object.
:param current_time: datetime object, containing the current datetime
:param current_rate: Rate, calculated based on pricing settings in ask_strategy.
:param current_profit: Current profit (as ratio), calculated based on current_rate.
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
:return float: New stoploss value, relative to the currentrate
"""
return -0.05
# Optimal timeframe for the strategy.
timeframe = '1h'
# Run "populate_indicators()" only for new candle.
process_only_new_candles = True
# These values can be overridden in the config.
use_exit_signal = True
exit_profit_only = False
ignore_roi_if_entry_signal = False
# Hyperoptable parameters
# Number of candles the strategy requires before producing valid signals
startup_candle_count: int = 30
# Optional order type mapping.
order_types = {
'entry': 'limit',
'exit': 'limit',
'stoploss': 'market',
'stoploss_on_exchange': False
}
# Optional order time in force.
order_time_in_force = {
'entry': 'gtc',
'exit': 'gtc'
}
plot_config = {
'main_plot': {
'tenkan': {'color': 'red'},
'kijun': {'color': 'green'},
},
# 'subplots': {
# "MACD": {
# 'macd': {'color': 'blue'},
# 'macdsignal': {'color': 'orange'},
# },
# "RSI": {
# 'cloud_green': {'color': 'red'},
# }
# }
}
def informative_pairs(self):
"""
Define additional, informative pair/interval combinations to be cached from the exchange.
These pair/interval combinations are non-tradeable, unless they are part
of the whitelist as well.
For more information, please consult the documentation
:return: List of tuples in the format (pair, interval)
Sample: return [("ETH/USDT", "5m"),
("BTC/USDT", "15m"),
]
"""
return []
@property
def protections(self):
return [
{
"method": "CooldownPeriod",
"stop_duration_candles": 5
}
]
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
ichi = ichimoku(dataframe)
dataframe['tenkan'] = ichi['tenkan_sen']
dataframe['kijun'] = ichi['kijun_sen']
dataframe['senkou_a'] = ichi['senkou_span_a']
dataframe['senkou_b'] = ichi['senkou_span_b']
dataframe['cloud_green'] = ichi['cloud_green']
dataframe['cloud_red'] = ichi['cloud_red']
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Based on TA indicators, populates the entry signal for the given dataframe
:param dataframe: DataFrame
:param metadata: Additional information, like the currently traded pair
:return: DataFrame with entry columns populated
"""
dataframe.loc[
(
(
(dataframe['cloud_green']) &
(qtpylib.crossed_above(dataframe['close'], dataframe['senkou_a']))
)
|
(
(dataframe['cloud_red']) &
(qtpylib.crossed_above(dataframe['close'], dataframe['senkou_b']))
)
|
(
(qtpylib.crossed_above(dataframe['tenkan'], dataframe['kijun']))
)
),
'enter_long'] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Based on TA indicators, populates the exit signal for the given dataframe
:param dataframe: DataFrame
:param metadata: Additional information, like the currently traded pair
:return: DataFrame with exit columns populated
"""
dataframe.loc[
(
),
'exit_long'] = 0
return dataframe