EMA crossover strategy with freqtrade
Binance and multiple exchanges show different emas on their default settings, here we’ll showcase a strategy using a simple ema cross to see if we can obtain a profitable strategy on BTC pairs.
Check out our guide on how to install freqtrade before getting started!
We’ll need to create the emas we want to use, in this case, we just need a few lines on the function def populate_indicators:
dataframe['ema7'] = ta.EMA(dataframe, timeperiod = 7 ) dataframe['ema25'] = ta.EMA(dataframe, timeperiod = 25)
This will populate 2 columns on your pandas dataframe which will contain ema7 and ema25, now we want to create the buy logic, we’ll simply add the function on populate_buy_trend function as follows:
dataframe.loc[ ( ( (dataframe['ema7'] > dataframe['ema25']) & (dataframe['ema7'].shift(1) <= dataframe['ema25'].shift(1)) ) ), 'buy'] = 1
To clarify, the logic is simple, buy if in the current candle ema 7 is above ema 25 and if ema 7 was below or equal to ema25 in the last candle before the current one.
Now you can either reverse the condition to create a def populate_sell_trend (sell condition) or simply use roi 0.15 (15%) along with a stop loss of 10%. We’ll leave this small task to the reader, feel free to ask questions in our comment section or on our discord.
In the following days we’ll be releasing a post on how to backtest strategies using freqtrade.