Basic RSI Strategy - Beginner starting point.
Timeframe
5m
Direction
Long Only
Stoploss
-10.0%
Trailing Stop
No
ROI
0m: 4.0%, 30m: 2.0%, 60m: 1.0%
Interface Version
3
Startup Candles
N/A
Indicators
3
freqtrade/freqtrade-strategies
Strategy 003 author@: Gerald Lonlas github@: https://github.com/freqtrade/freqtrade-strategies
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
import numpy as np
import pandas as pd
from pandas import DataFrame
from freqtrade.strategy import IStrategy, IntParameter
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
class SampleStrategy(IStrategy):
"""
Basic RSI Strategy - Beginner starting point.
Buy when RSI < 30 (oversold), sell when RSI > 70 (overbought).
Results: 72.2% win rate but negative overall due to large losses.
See ImprovedStrategy.py for enhancements.
"""
INTERFACE_VERSION = 3
buy_rsi = IntParameter(20, 40, default=30, space="buy")
sell_rsi = IntParameter(60, 80, default=70, space="sell")
minimal_roi = {"60": 0.01, "30": 0.02, "0": 0.04}
stoploss = -0.10
trailing_stop = False
timeframe = "5m"
process_only_new_candles = True
startup_candle_count: int = 200
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe["rsi"] = ta.RSI(dataframe)
dataframe["ema_200"] = ta.EMA(dataframe, timeperiod=200)
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
dataframe["bb_lowerband"] = bollinger["lower"]
dataframe["bb_middleband"] = bollinger["mid"]
dataframe["bb_upperband"] = bollinger["upper"]
dataframe["volume_mean"] = dataframe["volume"].rolling(window=20).mean()
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
(dataframe["rsi"] < self.buy_rsi.value) &
(dataframe["close"] > dataframe["ema_200"]) &
(dataframe["volume"] > 0)
),
"enter_long",
] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
(dataframe["rsi"] > self.sell_rsi.value) &
(dataframe["volume"] > 0)
),
"exit_long",
] = 1
return dataframe