Strategy vault / Mean reversion
CCI Long Only Strategy
This strategy designs a long only trading strategy based on the CCI indicator. It generates buy signals when CCI is above 100 and closes long positions when CCI drops below -100. The strategy effectively prevents…

Overview
This strategy designs a long only trading strategy based on the CCI indicator. It generates buy signals when CCI is above 100 and closes long positions when CCI drops below -100. The strategy effectively prevents shorting by only allowing closing of long positions.
Strategy Logic
The CCI indicator is a trending oscillator that measures the deviation of current price from the typical price over a period. CCI above 100 suggests overbought conditions while CCI below -100 suggests oversold conditions.
The trading logic is to go long when CCI crosses above 100 and close the long position when CCI subsequently drops below -100. Additionally, the strategy only allows position closing to prevent short positions, effectively controlling risks.
Advantage Analysis
- Utilizes mature CCI techniques to identify overbought/oversold areas
- Prevents short side risks by only going long
- Customizable CCI parameters for optimization across products
- Simple logic easy to understand and implement
Risk Analysis
- CCI results sensitive to different parameters
- Need to incorporate more factors when taking CCI signals to avoid false signals
- Missing short side trading opportunities
- Vulnerable to price shocks from events
Optimization Directions
- Optimize CCI parameters for different products
- Add filters with more indicators to improve accuracy
- Incorporate stop loss strategy to limit losses
- Allow reopened signals for re-entry
- Allow measured short side trading to increase profits
Summary
The strategy identifies overbought/oversold areas with CCI for long only trading. The concept is mature and easy to implement but has risks around parameter optimization, signal filters, stops etc. With continuous improvements, it can become a robust long term trading strategy choice.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | CCI Period |
Source Pine Script
/*backtest
start: 2022-12-11 00:00:00
end: 2023-12-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("CCI Long Only Strategy", overlay=true)
// Input for CCI period
cciPeriod = input(14, title="CCI Period")
// Calculate CCI
cciValue = ta.cci(close, cciPeriod)
// Initialize variables to track last signals
var bool lastBuySignal = na
var bool lastSellSignal = na
// Buy condition
buyCondition = cciValue > 100 and na(lastBuySignal)
// Sell condition
sellCondition = cciValue < -100 and na(lastSellSignal)
// Update last signals
lastBuySignal := buyCondition ? true : na
lastSellSignal := sellCondition ? true : na
// Execute Buy and Sell orders
strategy.entry("Buy", strategy.long, when = buyCondition)
strategy.close("Buy", when = sellCondition)
// Plot CCI for reference
plot(cciValue, title="CCI", color=color.blue)Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-18. 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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/CCI-Long-Only-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- Extended Adaptive CCI Bottom Fishing Trading Strategy for CommoditiesPine Script · Mean reversion · 1h
- Four Indicator Momentum Reversal StrategyPine Script · Mean reversion · 45m
- Dual Indicator Reversal Trading StrategyPine Script · Mean reversion · 3h
- Dynamic Dual Technical Indicator Oversold Overbought Confirmation Trading StrategyPine Script · Mean reversion · 5m
- Moving Average Crossover and Reversal Indicator Combination StrategyPine Script · Mean reversion · 1d
- Multi Indicator Scoring Trading StrategyPine Script · Mean reversion · 1d