Strategy vault / Mean reversion
Long Term Trend Reversal Strategy
The long-term trend reversal strategy is a mechanical trading system that combines trend following and short-term reversals. It uses the 7-day high and low to build a channel and the 200-day moving average to…

Overview
The long-term trend reversal strategy is a mechanical trading system that combines trend following and short-term reversals. It uses the 7-day high and low to build a channel and the 200-day moving average to determine the long-term trend direction. In a bull market, it buys on dips and sells in uptrends. In a bear market, it sells on rallies and buys on dips.
Strategy Logic
The strategy is mainly based on the following principles:
Use the 7-day high-low to judge the rise and fall over the past week.
The 200-day moving average determines the long-term trend direction.
When the price breaks below the 7-day low and is above the 200-day moving average, a buy signal is generated. This indicates the end of the short-term downside correction and the trend may reverse upwards.
When the price breaks above the 7-day high and is below the 200-day moving average, a sell signal is generated. This indicates the end of the short-term upside correction and the trend may reverse downwards.
Use 2x ATR stop loss to control risk per trade.
The key is to consider both short-term and long-term timeframes. The 7-day channel judges recent price action and the 200-day MA judges the multi-month trend. Trading signals are only generated when both indicate the same direction. This avoids false signals from short-term corrections.
Advantage Analysis
The main advantages of this strategy are:
Simple and clear signals based on price and moving average. Easy to implement.
Considers both short-term and long-term trends, filters noise effectively.
Trend following and mean reversion combined smooths returns.
ATR stop loss controls risk, smaller max drawdown.
Applicable to stocks, forex, crypto across markets.
Can run in high and low frequency environments.
Risk Analysis
The main risks are:
May miss large trends in strong trending markets.
Stop loss may trigger frequently in choppy markets.
Improper parameters may lead to over-trading.
Improper short and long term trend metrics may filter too many signals.
Model failure due to out of sample data.
The main risk management techniques:
Optimize parameters for reasonable stop loss and trade frequency.
Robust backtesting across markets and time frames.
Portfolio diversification to lower single strategy risk.
Exponential stop loss to limit loss per trade.
Optimization Directions
The strategy can be improved on:
Optimize channel length for better short-term trend metric.
Optimize MA length for better long-term trend metric.
Try other stop loss techniques like percentage, trailing.
Add volume condition. Trend reversals often see increase in volume.
Machine learning to find optimal short and long term parameters.
Dynamic exit rules based on fundamentals and sentiment.
Optimize stop loss for exponential or profit locking algorithms.
Parameter optimization and combinations can further improve returns and risk metrics.
Summary
The long term trend reversal strategy combines both trend following and mean reversion. By judging both short-term and long-term trends, it generates signals at trend reversal points. Compared to pure trend or mean reversion strategies, it filters out market noise and achieves steady returns and risk control. Overall, this strategy suits algo traders with market views and provides stable performance for quantitative portfolios. With ongoing optimization and risk management, further improvements in risk-return are possible.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 7 | Channel Length |
| v_input_2 | 200 | Ma Length |
| v_input_3 | 2 | ATR Stop Loss |
Source Pine Script
/*backtest
start: 2023-11-05 00:00:00
end: 2023-11-12 00:00:00
period: 45m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © racer8
//@version=4
// This Algo Strategy Has Only 3 rules and 62% Win Rate (Youtube)
strategy("Trend Bounce", overlay=true)
nn = input(7,"Channel Length")
hi = highest(high,nn)
lo = lowest(low,nn)
n2 = input(200,"Ma Length")
ma = sma(close,n2)
if close>ma and close<lo[1]
strategy.entry("Buy",strategy.long)
if close>hi[1]
strategy.close("Buy")
if close<ma and close>hi[1]
strategy.entry("Sell",strategy.short)
if close<lo[1]
strategy.close("Sell")
plot(hi,"high",color=color.aqua)
plot(lo,"low",color=color.aqua)
plot(ma,"sma",color=color.yellow)
//-----------------------------------------Stop Loss-------------------------------------------------------
atr = sma(tr,10)[1]
bought = strategy.position_size[0] > strategy.position_size[1]
sold = strategy.position_size[0] < strategy.position_size[1]
slm = input(2.0,"ATR Stop Loss",minval=0)
StopPrice_Long = strategy.position_avg_price - slm*atr // determines stop loss's price
StopPrice_Short = strategy.position_avg_price + slm*atr // determines stop loss's price
FixedStopPrice_Long = valuewhen(bought,StopPrice_Long,0) // stores original StopPrice
FixedStopPrice_Short = valuewhen(sold,StopPrice_Short,0) // stores original StopPrice
plot(FixedStopPrice_Long,"ATR Stop Loss Long",color=color.blue,linewidth=1,style=plot.style_cross)
plot(FixedStopPrice_Short,"ATR Stop Loss Short",color=color.red,linewidth=1,style=plot.style_cross)
if strategy.position_size > 0
strategy.exit(id="Stop", stop=FixedStopPrice_Long) // commands stop loss order to exit!
if strategy.position_size < 0
strategy.exit(id="Stop", stop=FixedStopPrice_Short) // commands stop loss order to exit!
Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-13. 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/Long-Term-Trend-Reversal-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 Combining Dynamic Trend Reversal and Stochastic IndicatorPine Script · Mean reversion · 1d
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d
- Advanced Quantitative Trend Following and Cloud Reversal Composite Trading StrategyPine Script · Mean reversion · 1d
- Advanced Strategy with Volume and Price Pullback Multiple Take ProfitPine Script · Mean reversion · 1h
- Bidirectional Moving Average Reversion Trading StrategyPine Script · Mean reversion · 1h
- Bollinger Bands ATR Risk Reward Trading StrategyPine Script · Mean reversion · 1d