0bps

Strategy vault / Mean reversion

Confirmed Divergence Strategy

The Confirmed Divergence Strategy utilizes the dual divergence signals from the RSI indicator and Awesome Oscillator to determine more reliable entry points. When prices form new highs or lows while the RSI and AO…

Author
ChaoZhang
Complexity
Intermediate · 103 lines
Parameters
9
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

IMG

Overview

The Confirmed Divergence Strategy utilizes the dual divergence signals from the RSI indicator and Awesome Oscillator to determine more reliable entry points. When prices form new highs or lows while the RSI and AO indicators form reversals of highs or lows, it is a divergence signal. This strategy requires divergence from both indicators at the same time to filter out some false signals and improve entry effectiveness.

Strategy Principle

This strategy judges buy and sell points based on the divergence between the magnitude of price rises and falls and the values of the RSI and AO indicators. The specific judgment methods are as follows:

Bullish divergence: prices form a newer low while RSI and AO form newer highs, that is, prices fall while RSI and AO rise, constituting a bullish divergence signal.

Bearish divergence: prices form a newer high while RSI and AO form newer lows, that is, prices rise while RSI and AO fall, constituting a bearish divergence signal.

The strategy requires both indicators to simultaneously meet the divergence criteria to avoid erroneous signals from false divergence of a single indicator. When the divergence signal is established, set a stop loss near the lower or upper rail of the Bollinger Bands, specifically just above the lower rail or just below the upper rail.

Advantage Analysis

This strategy has the following advantages:

  1. The double indicator filtering increases the reliability of signals and avoids false divergence signals from a single indicator.

  2. Using the divergence characteristics of indicators to determine buy and sell points has a relatively small chance of pullback.

  3. Divergence signals have good sustainability and greater profit potential.

  4. Setting stop loss near key support or resistance reduces the possibility of individual huge losses.

Risk Analysis

This strategy also has some risks:

  1. The conditions for double filtering are met less frequently, possibly missing some trading opportunities.

  2. Divergence is not a 100% reliable signal, and losses may occur in some individual situations.

  3. Improper parameter settings for Bollinger Bands can result in stop loss that is too loose or too tight.

Optimization Directions

This strategy can be optimized in several ways:

  1. Adjust the cycle parameters for judging divergence to optimize parameters for divergence signals.

  2. Test different stop loss methods such as trailing stop or dynamic stop loss.

  3. Increase filtering by other indicators such as trading volume to further improve signal reliability.

  4. Comprehensively consider trends, support/resistance and other factors to identify the quality of divergence signals.

Summary

The Confirmed Divergence Strategy determines entry points through the dual divergence signals of RSI and AO. The double filtering mechanism effectively reduces false signals and increases profitability. The strategy also sets stop loss at key levels to control risks, with good risk-reward characteristics. By means of parameter optimization, increased signal filtering, etc., the stability and trading effect of the strategy can be further enhanced.

Parameters

NameDefaultWhat it controls
v_input_130length
v_input_22mult
v_input_314RSI period
v_input_470Overbought Level
v_input_530Oversold Level
v_input_65Awesome Short MA
v_input_734Awesome Long MA
v_input_85short lookback period
v_input_925long lookback period

Source Pine Script

/*backtest
start: 2023-12-15 00:00:00
end: 2024-01-14 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("Confirmed Divergence Strategy", overlay=true)
source = close
length = input(30, minval=1)
mult = input(2.0, minval=0.001, maxval=50)
// SETTING UP VARIABLES //

src = close

// RSI //
rsiprd = input(title="RSI period",defval=14)
rv = rsi(src,rsiprd)
ob = input(title="Overbought Level",  defval=70)
os = input(title="Oversold Level",  defval=30)
lengthAO1=input(title="Awesome Short MA", defval=5, minval=1) //5 periods
lengthAO2=input(title="Awesome Long MA", defval=34, minval=1) //34 periods


//Awesome//

AO = sma((high+low)/2, lengthAO1) - sma((high+low)/2, lengthAO2)

// look back periods //
x = input(title = "short lookback period",defval=5)
z = input(title = "long lookback period",defval=25)


// END SETUP //

////////////////////////
// BULLISH DIVERGENCE //
////////////////////////

// define lower low in price //

srcLL = src > lowest(src,x) and  lowest(src,x)<lowest(src,z)[x]

// define higher low in rsi //

rsiHL = rv>lowest(rv,x) and lowest(rv,x) > lowest(rv,z)[x] and lowest(rv,z)<os

// define higher low in AO //


aoHL = AO > lowest(AO,x) and lowest(AO,x) > lowest(AO,z)[x] and lowest(AO, x) < 0



BullishDiv = srcLL and rsiHL and aoHL


////////////////////////
// BEARISH DIVERGENCE //
////////////////////////

// define higher high in price //

srcHH = src < highest(src,x) and  highest(src,x)>highest(src,z)[x]

// define lower high in RSI //

rsiLH = rv<highest(rv,x) and highest(rv,x) < highest(rv,z)[x] and highest(rv,z)>ob

// define lower high in AO //
aoLH = AO<highest(AO,x) and highest(AO,x) < highest(AO,z)[x] and highest(AO, x) > 0

BearishDiv = srcHH and rsiLH and aoLH


basis = sma(source, length)
dev = mult * stdev(source, length)

upper = basis + dev
lower = basis - dev



if (BullishDiv)
    strategy.entry("DivLE", strategy.long, stop=lower, oca_name="BullishDiv",comment="DivLE")
else
    strategy.cancel(id="DivLE")
    
if (crossover(close, lower))
    strategy.close("DivSE")
    
if (crossunder(close, upper))
    strategy.close("DivLE")

if (BearishDiv)
    strategy.entry("DivSE", strategy.short, stop=upper, oca_name="BearishDiv",comment="DivSE")
else
    strategy.cancel(id="DivSE")

//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)

Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-15. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Confirmed-Divergence-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open