Files
freqtrade-strategies/user_data/strategies/MultiMa.py
T

100 lines
3.4 KiB
Python
Raw Normal View History

# MultiMa Strategy V2
2021-05-18 22:13:53 +04:30
# Author: @Mablue (Masoud Azizi)
# github: https://github.com/mablue/
2021-05-18 22:13:53 +04:30
# --- Do not remove these libs ---
2022-05-31 06:43:02 +02:00
from freqtrade.strategy import IntParameter, IStrategy
2021-05-18 22:13:53 +04:30
from pandas import DataFrame
2021-09-23 21:34:14 +10:00
2021-05-18 22:13:53 +04:30
# --------------------------------
# Add your lib to import here
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
from functools import reduce
class MultiMa(IStrategy):
# 111/2000: 18 trades. 12/4/2 Wins/Draws/Losses. Avg profit 9.72%. Median profit 3.01%. Total profit 733.01234143 USDT ( 73.30%). Avg duration 2 days, 18:40:00 min. Objective: 1.67048
2021-05-18 22:13:53 +04:30
INTERFACE_VERSION: int = 3
# Buy hyperspace params:
buy_params = {
"buy_ma_count": 4,
"buy_ma_gap": 15,
}
2021-05-18 22:13:53 +04:30
# Sell hyperspace params:
sell_params = {
"sell_ma_count": 12,
"sell_ma_gap": 68,
}
2021-05-18 22:13:53 +04:30
# ROI table:
minimal_roi = {
"0": 0.523,
"1553": 0.123,
"2332": 0.076,
"3169": 0
}
2021-05-18 22:13:53 +04:30
# Stoploss:
stoploss = -0.345
2021-05-18 22:13:53 +04:30
# Trailing stop:
trailing_stop = False # value loaded from strategy
trailing_stop_positive = None # value loaded from strategy
trailing_stop_positive_offset = 0.0 # value loaded from strategy
trailing_only_offset_is_reached = False # value loaded from strategy
# Opimal Timeframe
2021-09-23 21:34:14 +10:00
timeframe = "4h"
2021-05-18 22:13:53 +04:30
count_max = 20
gap_max = 100
buy_ma_count = IntParameter(1, count_max, default=7, space="buy")
buy_ma_gap = IntParameter(1, gap_max, default=7, space="buy")
sell_ma_count = IntParameter(1, count_max, default=7, space="sell")
sell_ma_gap = IntParameter(1, gap_max, default=94, space="sell")
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
for count in range(self.count_max):
for gap in range(self.gap_max):
if count*gap > 1 and count*gap not in dataframe.keys():
dataframe[count*gap] = ta.TEMA(
dataframe, timeperiod=int(count*gap)
)
print(" ", metadata['pair'], end="\t\r")
2021-05-19 10:22:41 +04:30
2021-05-18 22:13:53 +04:30
return dataframe
2022-07-10 11:34:40 +02:00
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
2021-05-18 22:13:53 +04:30
conditions = []
# I used range(self.buy_ma_count.value) instade of self.buy_ma_count.range
# Cuz it returns range(7,8) but we need range(8) for all modes hyperopt, backtest and etc
for ma_count in range(self.buy_ma_count.value):
key = ma_count*self.buy_ma_gap.value
past_key = (ma_count-1)*self.buy_ma_gap.value
if past_key > 1 and key in dataframe.keys() and past_key in dataframe.keys():
conditions.append(dataframe[key] < dataframe[past_key])
2021-05-18 22:13:53 +04:30
if conditions:
2022-07-10 11:34:40 +02:00
dataframe.loc[reduce(lambda x, y: x & y, conditions), "enter_long"] = 1
2021-05-18 22:13:53 +04:30
return dataframe
2022-07-10 11:34:40 +02:00
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
2021-05-18 22:13:53 +04:30
conditions = []
for ma_count in range(self.sell_ma_count.value):
key = ma_count*self.sell_ma_gap.value
past_key = (ma_count-1)*self.sell_ma_gap.value
if past_key > 1 and key in dataframe.keys() and past_key in dataframe.keys():
conditions.append(dataframe[key] > dataframe[past_key])
2021-05-18 22:13:53 +04:30
if conditions:
2022-07-10 11:34:40 +02:00
dataframe.loc[reduce(lambda x, y: x | y, conditions), "exit_long"] = 1
2021-05-18 22:13:53 +04:30
return dataframe