Strategy vault / Trend following
DiNapoli Detrended Oscillator Strategy
This strategy generates trading signals based on the DiNapoli Detrended Oscillator. It reflects overbought/oversold levels by the difference between price and moving average, aiming to identify reversal…
Overview
This strategy generates trading signals based on the DiNapoli Detrended Oscillator. It reflects overbought/oversold levels by the difference between price and moving average, aiming to identify reversal opportunities. Signals are generated when the oscillator crosses a threshold.
Strategy Logic
The key components are:
Moving average: Calculates the trend baseline.
Difference indicator: Price minus moving average forms the oscillator.
Threshold line: Crossing this level triggers signals.
Long signal: Oscillator crossing above threshold.
Short signal: Oscillator crossing below threshold.
Reverse option: Flips the long/short signals.
The strategy aims to capture short-term reversals by identifying divergences between price and trend. The logic is simple and intuitive.
Advantages
Compared to other reversal strategies, the advantages are:
Simple and intuitive logic, easy to implement.
Minimal parameters, convenient backtesting.
Flexibility in parameter tuning for different periods.
Reverse option adaptable to different markets.
Clear stops and exits control risk.
Relatively small drawdowns, tunable through parameters.
Potential to optimize with machine learning.
Overall good risk/reward profile for short-term trading.
Risks
However, the main risks are:
Over-reliance on parameter optimization risks overfitting.
Lagging in moving average and oscillator.
Lack of confirmation from other variables.
Timing effect may degrade across changing markets.
Difficult to persistently generate alpha, requires frequent adjustments.
Need to monitor reward/risk ratios and curve smoothness.
High trade frequency increases transaction costs.
Robustness across markets requires validation.
Enhancements
Based on the analysis, enhancements may involve:
Testing different moving average parameters.
Adding volume confirmation.
Implementing stops and exits to control risk.
Evaluating robustness across different markets and timeframes.
Rolling window backtesting for continual verification.
Adjusting position sizing to lower frequency.
Incorporating machine learning for better parameters.
Optimizing overall risk management strategies.
Continual iterations to adapt to changing markets.
Conclusion
In summary, this is a relatively simple mean-reversion strategy idea. Proper parameter tuning can yield decent results. But preventing overfitting and achieving persistent success require ongoing backtesting, optimization and enhancements from multiple dimensions.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | Length |
| v_input_2 | false | Trigger |
| v_input_3 | true | Trade reverse |
Source Pine Script
/*backtest
start: 2023-08-23 00:00:00
end: 2023-09-22 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version = 2
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 05/12/2016
// DiNapoli Detrended Oscillator Strategy
// You can change long to short in the Input Settings
// Please, use it only for learning or paper trading. Do not for real trading.
////////////////////////////////////////////////////////////
strategy(title="DiNapoli Detrended Oscillator Strategy Backtest")
Length = input(14, minval=1)
Trigger = input(0)
reverse = input(true, title="Trade reverse")
hline(Trigger, color=gray, linestyle=line)
xSMA = sma(close, Length)
nRes = close - xSMA
pos = iff(nRes > Trigger, 1,
iff(nRes <= Trigger, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
plot(nRes, color=blue, title="DiNapoli")
barcolor(possig == -1 ? red: possig == 1 ? green : blue )Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-23. 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/DiNapoli-Detrended-Oscillator-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
- Adaptive Trading Strategy Based on Stochastic RSI Dual Line CrossoverPine Script · Trend following · 4h
- Dual Moving Average Convergence Trend Tracking StrategyPine Script · Trend following · 1d
- Dual SMA Crossover StrategyPine Script · Trend following · 5m
- Dynamic Moving Average and Bollinger Bands Cross Strategy with Fixed Stop Loss Optimization ModelPine Script · Trend following · 3h
- Dynamic Signal Line Trend Following Strategy Combining ATR and VolumePine Script · Trend following · 1h
- EMA SMA Trend Following with Swing Trading Strategy Combined Volume Filter and Percentage Take Profit Stop Loss SystemPine Script · Trend following · 1d