There are multiple ideas that you can use to trade with Ichimoku Cloud, we’ll trade using Tenkan over Kijun cross along with using the color of the ichimoku cloud at given candle.
We need to install custom indicators, you can read here how to do so.
Strategy
The strategy is fairly simple, we will use the timeframe of 15 minutes and will buy when Tenkan crosses Kijun and the Ichimoku Cloud is Red, it will then take profits at 100% or trail the stop loss to 5% from entry price as soon as it reaches 20% from initial buy price.
This is how the strategy would look like on tradingview:
[tv-ideaview idea=”YHToFHfR” width=”980″ height=”980″ language=”en”]
Instructions
After the installation it should be fairly simple. Copy test_strategy.py located on freqtrade/user_data/strategies to ichimoku.py:
user@computer:~/freqtrade$ cp user_strategies/strategies/test_strategy.py user_strategies/strategies/ichimoku.py
After that, modify the ichimoku.py with your preferred editor. Add the following line below import numpy:
from technical.indicators import ichimoku
Modify the class name to ichis, it will look like this:
class ichis(IStrategy):
For roi and stop-loss, we’ll use the following settings:
minimal_roi = {
"0": 1
}
stoploss = -0.1
trailing_stop = True
trailing_stop_positive = -0.15
trailing_stop_positive_offset = 0.20
trailing_only_offset_is_reached = True
This means that the strategy will take profit at 100% profit, initially it will set a stop loss of -10% and will trail the stop when it reaches 20% profits by moving the stop-loss to -15% from the 20% point, and then it will trail it with the highest reached price.
Find the function def populate_indicators and add the following lines:
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']
Find the def populate_buy_trend function and add:
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
(dataframe['tenkan'].shift(1)<dataframe['kijun'].shift(1)) &
(dataframe['tenkan']>dataframe['kijun']) &
(dataframe['cloud_red']==True)
),
'buy'] = 1
return dataframe
For the function def populate_sell_trend you can leave it empty as we’ll use ROI or Trailing stop-loss to sell the position rather than a specific sell trigger. It should look like this:
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
),
'sell'] = 1
return dataframe
Now you should be able to backtest the strategy and modify accordingly to your preferences. You can read more about backtesting here and about the ichimoku cloud here.
berlinguyinca
credit should be given to the codes of freqtrade a d technical
CryptoCue
Hey Berlinguyinca, we appreaciate the work from freqtrade along with your own repository. We do cite the freqtrade technical github in the post where we explain how to add custom indicators.
James
I get these error , I cant see anything diff between your post anf my “py” script/file
” ichi=ichimoku(dataframe)
NameError: name ‘dataframe’ is not defined”
CryptoCue
Please share your strategy file on a pastebin link and we’ll take a look.
Chirayu
Getting error, seems like trailing_stop_positive can have a value below zero. Is -0.15 the correct value?
2020-04-24 21:21:20,494 – freqtrade.configuration.config_validation – CRITICAL – Invalid configuration. See config.json.example. Reason: -0.15 is less than the minimum of 0
Failed validating ‘minimum’ in schema[‘properties’][‘trailing_stop_positive’]:
{‘maximum’: 1, ‘minimum’: 0, ‘type’: ‘number’}
On instance[‘trailing_stop_positive’]:
-0.15
2020-04-24 21:21:20,497 – freqtrade – ERROR – Fatal exception!
Traceback (most recent call last):
File “/freqtrade/freqtrade/main.py”, line 36, in main
return_code = args[‘func’](args)
File “/freqtrade/freqtrade/commands/optimize_commands.py”, line 48, in start_backtesting
backtesting = Backtesting(config)
File “/freqtrade/freqtrade/optimize/backtesting.py”, line 80, in __init__
validate_config_consistency(stratconf)
File “/freqtrade/freqtrade/configuration/config_validation.py”, line 80, in validate_config_consistency
validate_config_schema(conf)
File “/freqtrade/freqtrade/configuration/config_validation.py”, line 58, in validate_config_schema
raise ValidationError(
jsonschema.exceptions.ValidationError: -0.15 is less than the minimum of 0
CryptoCue
Trailing stop is now a positive value so it needs to be higher than 0.