Strategy vault / Trend following
Trend Following Strategy Based on Renko Moving Average
This is a trading strategy that utilizes Renko moving averages for trend identification and tracking. The core logic of this strategy is to go long or short when the price breaks through the 22-period HL2 moving…

Overview
This is a trading strategy that utilizes Renko moving averages for trend identification and tracking. The core logic of this strategy is to go long or short when the price breaks through the 22-period HL2 moving average on the Renko bars. Meanwhile, this strategy also sets risk management mechanisms like stop loss, take profit and trailing stop.
Strategy Principle
When the Renko bar closing price breaks above the 22-period HL2 moving average, go long. When the Renko bar closing price breaks below the 22-period HL2 moving average, go short. By judging the relationship between price and moving average, it captures the trend direction.
The HL2 moving average (Highest High + Lowest Low)/2) is a trend-following moving average, which incorporates the information of highest high and lowest low prices to more accurately determine the trend direction. 22 is an empirical value to balance the sensitivity of the moving average.
In addition, the strategy also sets the restriction of only opening positions during specific trading sessions to avoid potential huge market swings.
Advantage Analysis
This is a relatively simple and intuitive trend-following strategy with the pros below:
Using Renko bars as trading signals can effectively filter out market noise and capture the main trend.
The HL2 moving average combines highest and lowest price information for more reliable trend judgment.
Setting fixed stop loss and take profit points can well control the risk of single trades.
Trailing stop can lock in profits along the trend development to realize trend tracking.
Limiting trading sessions can alleviate the impact of huge swings to some extent.
Risk Analysis
There are also some risks with this strategy:
Moving average strategies tend to generate more false signals.
It cannot effectively cope with the gap risk caused by sudden events.
Improper Renko settings may miss better trading opportunities.
Fixed stop loss and take profit cannot adapt to market changes.
Optimization Directions
The strategy can be optimized in the following aspects:
Add other indicators or conditions to filter out false signals, e.g. volume, oscillators etc.
Test moving averages with different parameters to find out the most suitable period.
The box size of Renko can also be tested and optimized for the best parameter.
Add adaptive stop loss mechanism based on volatility.
Test different trading session settings to optimize this condition.
Conclusion
In conclusion, this is a simple and practical strategy for trend identification and tracking using Renko moving average. It has intuitive trading logic and risk control mechanisms, suitable for traders seeking steady returns. But there is still room for improvement by parameter optimization, adding filter conditions, adaptive stop loss etc. to obtain better strategy performance.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 300 | Take Profit |
| v_input_2 | 200 | Stop Loss |
| v_input_3 | 200 | Trailing Stop |
| v_input_4 | false | Trailing Stop Offset |
| v_input_5 | 0500-1600 | My Defined Hours |
Source Pine Script
/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("HL2 - 22 Cross", overlay=true)
// Stops and Profit inputs
inpTakeProfit = input(defval = 300, title = "Take Profit", minval = 0)
inpStopLoss = input(defval = 200, title = "Stop Loss", minval = 0)
inpTrailStop = input(defval = 200, title = "Trailing Stop", minval = 0)
inpTrailOffset = input(defval = 0, title = "Trailing Stop Offset", minval = 0)
// Stops and Profit Targets
useTakeProfit = inpTakeProfit >= 1 ? inpTakeProfit : na
useStopLoss = inpStopLoss >= 1 ? inpStopLoss : na
useTrailStop = inpTrailStop >= 1 ? inpTrailStop : na
useTrailOffset = inpTrailOffset >= 1 ? inpTrailOffset : na
//Specific Time to Trade
myspecifictradingtimes = input('0500-1600', title="My Defined Hours")
longCondition1 = crossover(close, ema(hl2, 22))
longCondition2 = time(timeframe.period, myspecifictradingtimes) != 0
if longCondition1 and longCondition2
strategy.entry("Long", strategy.long, comment="LongEntry")
shortCondition1 = crossunder(close, ema(hl2, 22))
shortCondition2 = time(timeframe.period, myspecifictradingtimes) != 0
if shortCondition1 and shortCondition2
strategy.entry("Short", strategy.short, comment="ShortEntry")
strategy.exit("Exit Long", from_entry = "Long", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)
strategy.exit("Exit Short", from_entry = "Short", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Trend-Following-Strategy-Based-on-Renko-Moving-Average.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
- 200 EMA VWAP MFI Trend Following StrategyPine Script · Trend following · 1d
- 4 EMA Trend StrategyPine Script · Trend following · 1d
- ADX MA and EMA Long Only Trend Tracking StrategyPine Script · Trend following · 1d
- ATR Dynamic Trend Following and EMA Crossover Trading StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h
- ATR and T3 Moving Average StrategyPine Script · Trend following · 5m