I found this on the next link: Back Testing RSI Divergence Strategy on FX

The author of the post used the exponential moving average for RSI calculation, using this piece of code:

'''
Assuming you have a pandas OHLC Dataframe downloaded from Metatrader 5 historical data. 
'''
# Get the difference in price from previous step
Data = pd.DataFrame(Data)
delta = Data.iloc[:, 3].diff()
delta = delta[1:]

# Make the positive gains (up) and negative gains (down) Series
up, down = delta.copy(), delta.copy()
up[up < 0] = 0
down[down > 0] = 0
roll_up = pd.stats.moments.ewma(up, lookback)
roll_down = pd.stats.moments.ewma(down.abs(), lookback)

# Calculate the SMA
roll_up = roll_up[lookback:]
roll_down = roll_down[lookback:]
Data = Data.iloc[lookback + 1:,].values

# Calculate the RSI based on SMA
RS = roll_up / roll_down
RSI = (100.0 - (100.0 / (1.0 + RS)))
RSI = np.array(RSI)
RSI = np.reshape(RSI, (-1, 1))

Data = np.concatenate((Data, RSI), axis = 1)

At this point we have an array with OHLC data and a fifth column that has the RSI in it. Then added the next two columns:

  1. Column 6: Data[:, 5] will be for the bullish divergences and will have values of 0 or 1 (initiate buy).
  2. Column 7: Data[:, 6] will be for the bearish divergences and will have values of 0 or -1 (initiate short).

using this variables:

lower_barrier = 30
upper_barrier = 70
width = 10

Here is the code:

# Bullish Divergence
for i in range(len(Data)):
   try:
       if Data[i, 4] < lower_barrier:
           for a in range(i + 1, i + width):
               if Data[a, 4] > lower_barrier:
                    for r in range(a + 1, a + width):
                       if Data[r, 4] < lower_barrier and \
                        Data[r, 4] > Data[i, 4] and Data[r, 3] < Data[i, 3]:
                            for s in range(r + 1, r + width): 
                                if Data[s, 4] > lower_barrier:
                                    Data[s + 1, 5] = 1
                                    break
                                else:
                                    continue
                        else:
                            continue
                    else:
                        continue
                else:
                    continue
  except IndexError:
        pass

# Bearish Divergence
for i in range(len(Data)):
   try:
       if Data[i, 4] > upper_barrier:
           for a in range(i + 1, i + width): 
               if Data[a, 4] < upper_barrier:
                   for r in range(a + 1, a + width):
                       if Data[r, 4] > upper_barrier and \
                       Data[r, 4] < Data[i, 4] and Data[r, 3] > Data[i, 3]:
                           for s in range(r + 1, r + width):
                               if Data[s, 4] < upper_barrier:
                                   Data[s + 1, 6] = -1
                                   break
                               else:
                                   continue
                       else:
                           continue
                   else:
                       continue
               else:
                   continue
   except IndexError:
       pass
Answer from robbinc91 on Stack Overflow
🌐
GitHub
github.com › thierryjmartin › freqtrade-stuff › blob › main › RSIDivergence.py
freqtrade-stuff/RSIDivergence.py at main · thierryjmartin/freqtrade-stuff
study(title="Divergence Indicator", format=format.price, resolution="") len = input(title="RSI Period", minval=1, defval=14) src = input(title="RSI Source", defval=close) lbR = input(title="Pivot Lookback Right", defval=5) # lookahead ·
Author   thierryjmartin
🌐
Freqtrade
freqtrade.io › en › stable › strategy-customization
Strategy Customization - Freqtrade
With this section, you have a new column in your dataframe, which has 1 assigned whenever RSI is above 30. Freqtrade uses this new column as an entry signal, where it is assumed that a trade will subsequently open on the next open candle.
Discussions

Creating a complex (maybe basic but strong ) strategy
I have backtested this strategy ... write a freqtrade strategy. ... will identify support and resist points (tolerance will be given manual or can be define as parameter like %2 - smthnelse) if price touches support/resist , will save the ris value · if price touches 2. time support/resist , will compare with 1 rsi value. If 2. rsi value is bigger than 1. rsi value that means (if support level long - if resist level short position) this is something like is rsi divergence but stronger ... More on github.com
🌐 github.com
2
July 27, 2024
algorithm - How to implement RSI Divergence in Python - Stack Overflow
I was wondering is there any Python library that covers RSI-Divergence (difference between a fast and a slow RSI) or any guidence about how can I implement its algorithm in Python. Already asked qu... More on stackoverflow.com
🌐 stackoverflow.com
Coding price-RSI divergence?
That might help with the extrema. https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.argrelextrema.html - The idea could look good in backtesting (depending on the quality of the backtest), but the relative maxima and minima will be lagging behind. In other words you will never know if the current bar is a extrema instantly. Depending on your settings it takes X bars more, before its recognisable as extrema. So you probably always miss the (perfect) entry / exit. If you trade crypto, checkout jesse: https://docs.jesse-ai.com/docs/indicators/reference.html#minmax - it offers the detection of extrema already and is a good backtesting framework. More on reddit.com
🌐 r/algotrading
3
7
June 7, 2020
Stochastic and RSI Strategy
For requestion a new strategy. Please use the template below. Any strategy request that does not follow the template will be closed. I am using 3 indicators in trading view and i found out that whe... More on github.com
🌐 github.com
2
May 12, 2021
🌐
Medium
medium.com › @sol_98230 › rsi-5-basic-strategies-4-steps-how-to-connect-it-to-the-trading-bot-a2aa5bb70f6c
RSI: 5 basic strategies, 4 steps, how to connect it to the trading Bot. | by Anastasia 3commas | Medium
October 12, 2018 - For a start, it is enough to know 5 basic strategies: Overbought and oversold. When the price goes into overbought or oversold zones, this may indicate a quick trend change. Divergence.
🌐
GitHub
github.com › freqtrade › freqtrade › issues › 10462
Creating a complex (maybe basic but strong ) strategy · Issue #10462 · freqtrade/freqtrade
July 27, 2024 - I have backtested this strategy ... write a freqtrade strategy. ... will identify support and resist points (tolerance will be given manual or can be define as parameter like %2 - smthnelse) if price touches support/resist , will save the ris value · if price touches 2. time support/resist , will compare with 1 rsi value. If 2. rsi value is bigger than 1. rsi value that means (if support level long - if resist level short position) this is something like is rsi divergence but stronger ...
Author   rcpislr
Top answer
1 of 4
3

I found this on the next link: Back Testing RSI Divergence Strategy on FX

The author of the post used the exponential moving average for RSI calculation, using this piece of code:

'''
Assuming you have a pandas OHLC Dataframe downloaded from Metatrader 5 historical data. 
'''
# Get the difference in price from previous step
Data = pd.DataFrame(Data)
delta = Data.iloc[:, 3].diff()
delta = delta[1:]

# Make the positive gains (up) and negative gains (down) Series
up, down = delta.copy(), delta.copy()
up[up < 0] = 0
down[down > 0] = 0
roll_up = pd.stats.moments.ewma(up, lookback)
roll_down = pd.stats.moments.ewma(down.abs(), lookback)

# Calculate the SMA
roll_up = roll_up[lookback:]
roll_down = roll_down[lookback:]
Data = Data.iloc[lookback + 1:,].values

# Calculate the RSI based on SMA
RS = roll_up / roll_down
RSI = (100.0 - (100.0 / (1.0 + RS)))
RSI = np.array(RSI)
RSI = np.reshape(RSI, (-1, 1))

Data = np.concatenate((Data, RSI), axis = 1)

At this point we have an array with OHLC data and a fifth column that has the RSI in it. Then added the next two columns:

  1. Column 6: Data[:, 5] will be for the bullish divergences and will have values of 0 or 1 (initiate buy).
  2. Column 7: Data[:, 6] will be for the bearish divergences and will have values of 0 or -1 (initiate short).

using this variables:

lower_barrier = 30
upper_barrier = 70
width = 10

Here is the code:

# Bullish Divergence
for i in range(len(Data)):
   try:
       if Data[i, 4] < lower_barrier:
           for a in range(i + 1, i + width):
               if Data[a, 4] > lower_barrier:
                    for r in range(a + 1, a + width):
                       if Data[r, 4] < lower_barrier and \
                        Data[r, 4] > Data[i, 4] and Data[r, 3] < Data[i, 3]:
                            for s in range(r + 1, r + width): 
                                if Data[s, 4] > lower_barrier:
                                    Data[s + 1, 5] = 1
                                    break
                                else:
                                    continue
                        else:
                            continue
                    else:
                        continue
                else:
                    continue
  except IndexError:
        pass

# Bearish Divergence
for i in range(len(Data)):
   try:
       if Data[i, 4] > upper_barrier:
           for a in range(i + 1, i + width): 
               if Data[a, 4] < upper_barrier:
                   for r in range(a + 1, a + width):
                       if Data[r, 4] > upper_barrier and \
                       Data[r, 4] < Data[i, 4] and Data[r, 3] > Data[i, 3]:
                           for s in range(r + 1, r + width):
                               if Data[s, 4] < upper_barrier:
                                   Data[s + 1, 6] = -1
                                   break
                               else:
                                   continue
                       else:
                           continue
                   else:
                       continue
               else:
                   continue
   except IndexError:
       pass
2 of 4
3

I changed above code a bit hope this helps:

lower_barrier = 30
upper_barrier = 70
width = 5
#Bullish Divergence
for i in range(len(Data)):

   try:
     if Data.iloc[i, 4] < lower_barrier:
         for a in range(i + 1, i + width):
             if Data.iloc[a, 4] > lower_barrier:
                  for r in range(a + 1, a + width):
                     if Data.iloc[r, 4] < lower_barrier and Data.iloc[r, 4] > Data.iloc[i, 4] and Data.iloc[r, 3] < Data.iloc[i, 3]:
                         for s in range(r + 1, r + width): 
                            if Data.iloc[s, 4] > lower_barrier:
                                print('Bullish above',Data.iloc[s+1,1])
                                Data.iloc[s + 1, 5] = 1
                                break
                            else:
                                continue
                    else:
                        continue
            else:
                continue
    else:
        continue
except IndexError:
    pass
#Bearish Divergence
for i in range(len(Data)):
try:
    if Data.iloc[i, 4] > upper_barrier:
        for a in range(i + 1, i + width): 
            if Data.iloc[a, 4] < upper_barrier:
                for r in range(a + 1, a + width):
                    if Data.iloc[r, 4] > upper_barrier and Data.iloc[r, 4] < Data.iloc[i, 4] and Data.iloc[r, 3] > Data.iloc[i, 3]:
                        for s in range(r + 1, r + width):
                            if Data.iloc[s, 4] < upper_barrier:
                                print('Bearish below',Data.iloc[s+1,2])
                                Data.iloc[s + 1, 6] = -1
                                break
                            else:
                                continue
                    else:
                        continue
                else:
                    continue
            else:
                continue
except IndexError:
    pass
🌐
Strat Ninja
strat.ninja › overview.php
RaposaDivergenceV1 - Strategy
When the required number of consecutive extrema is found, they are stored in a list and returned. Overall, the RaposaDivergenceV1 strategy combines the calculation of TA indicators, such as RSI, with the identification of price pattern extrema to generate buy and sell signals based on predefined conditions.
Find elsewhere
🌐
Snyk
snyk.io › advisor › freqtrade › functions › freqtrade.vendor.qtpylib.indicators.bollinger_bands
How to use the freqtrade.vendor.qtpylib.indicators.bollinger_bands function in freqtrade | Snyk
May 30, 2022 - freqtrade / freqtrade / freqtrade / strategy / default_strategy.py View on Github · # Minus Directional Indicator / Movement dataframe['minus_di'] = ta.MINUS_DI(dataframe) # Plus Directional Indicator / Movement dataframe['plus_di'] = ta.PLUS_DI(dataframe) # RSI dataframe['rsi'] = ta.RSI(dataframe) # Stoch fast stoch_fast = ta.STOCHF(dataframe) dataframe['fastd'] = stoch_fast['fastd'] dataframe['fastk'] = stoch_fast['fastk'] # Bollinger bands 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'] # EMA - Exponential Moving Average dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10) # SMA - Simple Moving Average dataframe['sma'] = ta.SMA(dataframe, timeperiod=40) return dataframe
🌐
New Trader U
newtraderu.com › home › rsi divergence cheat sheet
RSI Divergence Cheat Sheet - New Trader U
February 13, 2023 - An RSI divergence indicator signal shows traders when price action and the RSI are no longer showing the same momentum. The RSI shows the magnitude of a price move in a specific timeframe.
🌐
Freqst
freqst.com › strategy › 503545c89b313f33e0da2970e009b6b941cddbe05b2bdbe5c7d3e5a735e47ccccb3a0591f043e
Freqtrade - DIV_v1 Strategy Performance Results
This DIV_v1 strategy is an algo-trading strategy that uses the TA-Lib indicator library to identify potential trading opportunities. Specifically, it uses the RSI (Relative Strength Index) technical indicator to detect bullish divergence and the ohlc_bottom (the value of the open price, the ...
🌐
GitHub
github.com › freqtrade › freqtrade-strategies › issues › 176
Stochastic and RSI Strategy · Issue #176 · freqtrade/freqtrade-strategies
May 12, 2021 - Any strategy request that does not follow the template will be closed. I am using 3 indicators in trading view and i found out that when the StochRSI StochK crossing over StochD when the StochRSI value of under 20 and the RSI over 50 and the MACD with these settings over 0 there is a trend change to the upside.
Published   May 12, 2021
Author   pampos79
🌐
Strat Ninja
strat.ninja › overview.php
HarmonicDivergence - Strategy
These indicators include RSI (Relative Strength Index), Stochastic Oscillator, Rate of Change, Ultimate Oscillator, Awesome Oscillator, MACD (Moving Average Convergence Divergence), CCI (Commodity Channel Index), Chaikin Money Flow, On Balance Volume, MFI (Money Flow Index), ADX (Average Directional Index), ATR (Average True Range), Keltner Channels, Bollinger Bands, and various Exponential Moving Averages (EMA).
🌐
Reddit
reddit.com › r/algotrading › crypto investors, which strategy does your bot use in this particular market state?
r/algotrading on Reddit: Crypto investors, which strategy does your bot use in this particular market state?
December 6, 2019 -

Quick disclaimer before some of you insult me in the comments, I'm not looking for an easy way to make money. I'm just a programmer that thinks that cryptocurrencies and blockchain in general are the future and wants to learn from trading experts.

Having said so, I recently discovered Freqtrade and I fell in love with how beautiful its code is. I know something about trading but I'm certainly no expert and I wanted to get some information from people who definitely have more knowledge then me on what is the best trading strategy for the current market state and for other states in general.

🌐
Freqst
freqst.com › strategy › 2055b63d8765c8cabbd86cb8e9733cb3cdfbda505ded74b3ed281e4e93d411d338adfef89d2c0
Freqtrade - HarmonicDivergence Strategy Performance Results
The freqtrade strategy we are looking at here is based on analyzing the total bullish divergence of a currency, two bands check and the volume. The strategy works by first checking if the total bullish divergence of the currency has shifted significantly and then checks if two bands check is ...
🌐
Freqtrade
freqtrade.io › en › stable › strategy-advanced
Advanced Strategy - Freqtrade
These results are a consequence of the strategy overwriting prior tags - where the last tag will "stick" and will be the one freqtrade will use. Similar to Entry Tagging, you can also specify an exit tag. def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe["exit_tag"] = "" rsi_exit_signal = (dataframe["rsi"] > 70) ema_exit_signal = (dataframe["ema20"] < dataframe["ema50"]) # Additional conditions dataframe.loc[ ( rsi_exit_signal | ema_exit_signal # ...
🌐
YouTube
youtube.com › watch
Best RSI Trading Strategy for Algo Trading with Freqtrade (Full Tutorial) - YouTube
#freqtrade #rsi #strategy ''Freqtrade' ''RSI'' ''StrategyBest RSI Trading Strategy for Algo Trading with Freqtrade (Full Tutorial)Start Here: Build a Fully A...
Published   October 6, 2024
🌐
Freqst
freqst.com › strategy › 8c29807b15db26e0108b6c025cb2f9d3ec98b9f1555312403dcfd8e3d9c6fa0438adfef89d2c0
Freqtrade - MAC Strategy Performance Results
We appreciate your understanding and support during this transition. ... This is a MAC trading strategy that utilizes the Moving Average Convergence Divergence (MACD) indicator to determine when to open positions. It uses the RSI indicator to confirm if the trend is valid and whether a buy ...
🌐
Trading Heroes
tradingheroes.com › trading heroes › trading strategies › rsi divergence explained
RSI Divergence Explained - Trading Heroes
March 20, 2024 - The higher low in the RSI does not have to be in the oversold area for the signal to be valid. Here's an example of bullish divergence on the AUDCHF.
🌐
Medium
imbuedeskpicasso.medium.com › the-8787-roi-algo-strategy-unveiled-for-crypto-futures-22a5dd88c4a5
The 8787%+ ROI Algo Strategy Unveiled for Crypto Futures! Revolutionized With Famous RSI, MACD, Bollinger Bands, ADX, EMA | by Puranam Pradeep Picasso - ImbueDesk Profile | Medium
November 15, 2023 - At the heart of the strategy are three pivotal indicators: the RSI, MACD, and Bollinger Bands. Each plays a vital role in identifying potential trade opportunities. from functools import reduce from math import sqrt import numpy as np import pandas as pd from pandas import DataFrame from freqtrade.persistence import Trade import talib.abstract as ta def trade_signal(dataframe, rsi_tp = 14, bb_tp = 20): # Compute indicators dataframe['RSI'] = ta.RSI(dataframe['close'], timeperiod=rsi_tp) dataframe['upper_band'], dataframe['middle_band'], dataframe['lower_band'] = ta.BBANDS(dataframe['close'], t