0bps

Strategy vault / Trend following

OBV and CCI Indicators Based Trend Following Strategy

This strategy is a trend following strategy based on OBV and CCI indicators. It uses OBV indicator to judge market trend and capital flow, and then uses CCI indicator for filtering to generate trading signals. When…

Author
ChaoZhang
Complexity
Starter · 35 lines
Parameters
3
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

This strategy is a trend following strategy based on OBV and CCI indicators. It uses OBV indicator to judge market trend and capital flow, and then uses CCI indicator for filtering to generate trading signals. When both OBV and CCI indicators confirm the current uptrend, go long; when both indicators confirm the current downtrend, go short.

Strategy Logic

The strategy mainly relies on OBV and CCI two indicators. OBV indicator can reflect the capital flow in the market. When OBV is green, it means the current trend is capital inflow; when OBV is red, it means the current trend is capital outflow. The CCI indicator is used as a filter. By setting a threshold, when CCI is above threshold, it is considered a bull market; when CCI is below threshold, it is considered a bear market.

For entry signals, if last period OBV value is green (capital inflow) and CCI is above threshold (in a bull market), meanwhile OBV line crosses above its EMA line, a buy signal is generated.

For exit signals, if last period OBV value is red (capital outflow) and CCI is below threshold (in a bear market), meanwhile OBV line crosses below its EMA line, a sell signal is generated.

So by judging the major trend using OBV, filtering with CCI indicator, and combining them using EMA crossovers to generate concrete trading signals, the strategy realizes trend following.

Advantage Analysis

The main advantages of this strategy are:

  1. Using OBV to determine market capital flow and trend direction, avoiding short-term market noise interference;

  2. Leveraging CCI indicator for filtering, making trading signals more reliable;

  3. Using EMA crossovers to generate high quality concrete trading points;

  4. The rules are clear and simple, easy to understand and implement.

Risk Analysis

There are also some potential risks for this strategy:

  1. Possibility of OBV and CCI indicators generating wrong signals;

  2. Frequent trading signals, easy to overtrade;

  3. May be trapped during retracements;

  4. Poor parameter tuning leading to bad strategy performance.

To control these risks, methods like parameter optimization, adjusting trading frequency, setting stop loss and using filters can be applied.

Optimization Directions

The strategy can be optimized from the following aspects:

  1. Evaluate the impact of different parameters and find the optimal parameter combination;

  2. Set trading frequency limit to avoid over trading;

  3. Add stop loss mechanism to control single trade loss;

  4. Add other indicators as filters to improve signal quality;

  5. Optimize entry and exit logic to make trading signals more reliable.

Summary

In summary, this is a basic trend following strategy that can effectively track price trends and avoid noise interference. But there are still some risks, requiring improvements like parameter optimization, stop loss, trading frequency control etc. If parameters are set scientifically, significant backtest performance improvement can be achieved. The strategy suits more advanced quant traders for learning and practicing.

Parameters

NameDefaultWhat it controls
v_input_120CCI Length
v_input_2falseCCI threshold for OBV coding
v_input_313EMA length

Source Pine Script

/*backtest
start: 2023-02-14 00:00:00
end: 2024-02-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//author: SudeepBisht
//@version=3
strategy("SB_CCI coded OBV Strategy", overlay=true)

src = close
length = input(20, minval=1, title="CCI Length")
threshold=input(0, title="CCI threshold for OBV coding")
lengthema=input(13, title="EMA length")
obv(src) => 
    cum(change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume)
    
o=obv(src)
c=cci(src, length)
col=c>=threshold?green:red
chk=col==green?1:0
ema_line=ema(o,lengthema)

//plot(o, color=c>=threshold?green:red, title="OBV_CCI coded", linewidth=2)
//plot(ema(o,lengthema), color=orange, linewidth=2)


if (not na(ema_line))
    if (crossover(o, ema_line) and chk[1]==1)
        strategy.entry("RsiLE", strategy.long, comment="RsiLE")
    if (crossunder(o, ema_line) and chk[1]==0)
        strategy.entry("RsiSE", strategy.short, comment="RsiSE")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-21. 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/OBV-and-CCI-Indicators-Based-Trend-Following-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