
This strategy is a long-only trading system based on Renko charts combined with a time filtering mechanism designed for specific trading sessions. The strategy utilizes the Average True Range (ATR) to dynamically adjust the brick size, identifying uptrends by tracking bricks formed from price movements, and executing long trades only within specified trading hours. The core concept lies in using Renko charts to filter market noise, capture sustained price movements, while avoiding inactive market periods to improve trading efficiency and capital safety.
The strategy operates based on the following core principles:
Renko Brick Construction: The system determines brick size through two methods - fixed value or ATR-based dynamic adjustment. In ATR mode, the brick size equals the ATR value over a specific period (default 5) multiplied by a factor (default 1.0), allowing the brick size to adaptively adjust according to market volatility.
Direction Determination Logic: The strategy tracks price movements, forming an up-brick when the price rises above the previous brick’s closing price by more than the brick size; forming a down-brick when it falls by more than the brick size; and triggering a trend reversal when price movement exceeds twice the brick size.
Trade Signal Generation: A buy signal is generated when the brick direction changes from undefined or down to up; a sell signal is generated when the brick direction changes from undefined or up to down.
Time Filter: The strategy only executes trades within specified trading hours (default 4:35 to 14:30), which typically correspond to the active periods of major markets. When exiting the trading period, the system automatically closes positions to avoid overnight risk.
Long-Only Trading Mode: The strategy only executes long trades without short selling, suitable for markets with obvious bullish trends or where short selling is prohibited.
Based on code analysis, this strategy offers the following significant advantages:
Noise Filtering: Renko charts naturally have the ability to filter market noise, as new bricks are only formed when price movements exceed a specific threshold, effectively avoiding overreactions to small price fluctuations.
Adaptive Adjustment: By dynamically adjusting brick size through ATR, the strategy can adapt to different market environments and volatility conditions, increasing brick size during high volatility periods and decreasing it during low volatility periods.
Time Risk Management: The time filter ensures that trades are only conducted during the most active and liquid market periods, avoiding nighttime and early market sessions where liquidity might be insufficient or volatility abnormal.
Clear Direction: The strategy focuses on capturing uptrends with a concise and clear logic, avoiding the frequent trading and commission costs associated with alternating between long and short positions.
Visual Assistance: The strategy provides buy/sell signal labels and brick high/low point visualization options, allowing traders to intuitively understand market dynamics and strategy performance.
Capital Management: The strategy adopts a quantitative trading model based on capital, automatically calculating position size according to initial capital, reducing the complexity of capital management.
Despite its reasonable design, the strategy still has the following potential risks:
Lagging Response: Renko charts are inherently lagging indicators, as new brick formation requires price to reach a specific movement amplitude, potentially causing delays in entry and exit timing. In rapidly reversing markets, this may result in missing optimal trading points.
Lack of Short-term Flexibility: The strategy only generates signals when new bricks are formed, potentially missing short-term profit opportunities, especially performing poorly in oscillating markets.
Unidirectional Limitation: A long-only strategy cannot profit in declining markets and may even continuously lose money. When the market is in a long-term downtrend, strategy effectiveness significantly decreases.
Time Filter Risk: Fixed trading session settings might miss important opportunities outside trading hours, while potentially causing unnecessary closing and re-entry operations at trading session boundaries.
Parameter Sensitivity: Strategy performance is highly dependent on brick size parameter settings, and inappropriate parameter choices may lead to excessive trading or missed opportunities.
Solutions: - Add trend confirmation indicators such as moving averages or MACD to improve signal quality - Introduce stop-loss mechanisms to control maximum risk per trade - Consider adding short-selling functionality for bidirectional trading - Optimize the time filter to adjust trading sessions based on different market characteristics - Use parameter optimization testing to find the best parameter combinations
Based on code analysis, the strategy can be optimized in the following aspects:
Multi-indicator Fusion: Combine other technical indicators such as RSI, MACD, or moving average crossovers as confirmation signals to improve entry quality. This avoids false signals solely based on price patterns, especially in oscillating markets.
Dynamic Stop-Loss Mechanism: Introduce trailing stop-loss functionality, such as ATR-based dynamic stops, to protect profits while preserving upside potential. This is particularly important for capturing major trends.
Bidirectional Trading Extension: Add short trading capabilities to allow the strategy to profit in declining markets, improving the strategy’s all-weather adaptability.
Intelligent Time Filtering: Upgrade fixed time filtering to dynamic time filtering based on market activity, for example by integrating volume analysis, trading actively during high liquidity periods and conservatively during low liquidity periods.
Multi-timeframe Analysis: Introduce multi-timeframe analysis, such as using higher timeframe trend direction as a trading filter condition, only trading when the larger trend direction is consistent.
Optimized Parameter Adaptivity: Develop parameter adaptive mechanisms to dynamically adjust ATR period and multipliers based on market conditions, allowing the strategy to better adapt to different market environments.
Risk Exposure Control: Add position sizing algorithms to dynamically adjust trading size based on market volatility and signal strength, controlling risk exposure.
These optimization directions aim to improve the strategy’s robustness and adaptability, reducing losses in unfavorable market conditions while maximizing profit potential under favorable market conditions.
The Renko Time-Filtered Long-Only Trading Strategy is a trend-following system combining price momentum and time filtering. Through the Renko chart construction mechanism, the strategy effectively filters market noise, focusing on capturing sustained price movements; through the time filter, the strategy avoids inactive market periods, reducing overnight position risk.
The strategy’s main advantages lie in its concise and clear trading logic, adaptive brick size design, and strict time management, making it particularly suitable for markets with high volatility but an overall upward trend. However, its unidirectional trading characteristics and lagging response are limitations that need attention.
By introducing multi-indicator confirmation, dynamic stop-loss mechanisms, bidirectional trading capabilities, and intelligent time filtering optimizations, this strategy has the potential to further enhance its performance across different market environments. For investors seeking robust trading who are willing to sacrifice some flexibility in exchange for clearer trading signals, this is a strategy framework worth considering.
/*backtest
start: 2025-06-22 00:00:00
end: 2025-07-22 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT","balance":200000}]
args: [["RunMode",1,358374]]
*/
//@version=5
strategy("Renko Long-Only Strategy with Time Filter", overlay=true, default_qty_value = 10)
// --- 输入参数 ---
atrLength = input.int(5, "ATR Period", minval=1)//ATR周期
atrMult = input.float(1.0, "ATR Multiplier", minval=0.1, step=0.1)//ATR乘数
showWicks = input(false, "Show Wick Lines")//是否显示上下影线
showLabels = input(true, "Show Buy/Sell Labels")//是否显示买卖标签
// --- 交易时间设置(24小时制,从4:30 AM到2:30 PM)---
startHour = input.int(4, "Start Hour (24h)", minval=0, maxval=23)//开始交易小时
startMinute = input.int(30, "Start Minute", minval=0, maxval=59)//开始交易分钟
endHour = input.int(14, "End Hour (24h)", minval=0, maxval=23)//结束交易小时
endMinute = input.int(25, "End Minute", minval=0, maxval=59)//结束交易分钟
// --- 时间计算 ---
//检查当前是否在交易时间范围内
isTradingTime() =>
timeHour = hour(time("1"))//获取当前小时
timeMinute = minute(time("1"))//获取当前分钟
// 将时间转换为自午夜起的分钟数进行比较
currentTime = timeHour * 60 + timeMinute//当前时间(分钟)
sessionStart = startHour * 60 + startMinute//交易开始时间(分钟)
sessionEnd = endHour * 60 + endMinute//交易结束时间(分钟)
currentTime >= sessionStart and currentTime <= sessionEnd//判断是否在交易时间范围内
inTradingHours = isTradingTime()//当前是否在交易时间内
timeToClose = not inTradingHours and inTradingHours[1]//刚刚退出交易时间,需要平仓
// --- 砖块计算 ---
var float boxSize = na//砖块大小
var float lastClose = na//最后一个砖块的收盘价
var int direction = 0//方向:0=未定义,1=上涨,-1=下跌
var float wickHigh = na//上影线最高点
var float wickLow = na//下影线最低点
var bool newBrick = false//是否形成新砖块
var int prevDir = 0//前一个方向
// --- 全局信号变量 ---
var bool buySignal = false//买入信号
var bool sellSignal = false//卖出信号
// 更新基于ATR的砖块大小
boxSize :=ta.atr(atrLength) * atrMult//计算砖块大小
// 检测砖块形成条件
upMove = not na(lastClose) and (close - lastClose >= boxSize)//上涨移动
downMove = not na(lastClose) and (lastClose - close >= boxSize)//下跌移动
//反转条件:当前为上升趋势但下跌超过2倍砖块大小,或当前为下降趋势但上涨超过2倍砖块大小
reversal = (direction == 1 and downMove and (lastClose - close >= boxSize * 2)) or
(direction == -1 and upMove and (close - lastClose >= boxSize * 2))
// 生成新砖块
if na(lastClose)//初始化
lastClose := close//设置初始收盘价
wickHigh := high//设置初始最高价
wickLow := low//设置初始最低价
else if upMove and direction >= 0//继续上升趋势
lastClose := lastClose + boxSize//更新收盘价
prevDir := direction//保存前一个方向
direction := 1//设置当前方向为上升
wickHigh := high//更新上影线
wickLow := low//更新下影线
newBrick := true//标记形成新砖块
else if downMove and direction <= 0//继续下降趋势
lastClose := lastClose - boxSize//更新收盘价
prevDir := direction//保存前一个方向
direction := -1//设置当前方向为下降
wickHigh := high//更新上影线
wickLow := low//更新下影线
newBrick := true//标记形成新砖块
else if reversal//趋势反转
lastClose := direction == 1 ? lastClose - boxSize : lastClose + boxSize//根据当前方向反向更新收盘价
prevDir := direction//保存前一个方向
direction := direction * -1//反转方向
wickHigh := high//更新上影线
wickLow := low//更新下影线
newBrick := true//标记形成新砖块
else//没有新砖块形成
wickHigh := math.max(wickHigh, high)//更新上影线最高点
wickLow := math.min(wickLow, low)//更新下影线最低点
newBrick := false//标记没有形成新砖块
// 更新信号(必须在全局范围内)
buySignal := direction == 1 and prevDir != 1//方向从非上升变为上升时产生买入信号
sellSignal := direction == -1 and prevDir != -1//方向从非下降变为下降时产生卖出信号
// --- 策略逻辑 ---
// 只在形成新砖块、K线确认且在交易时间内进入
enterLong = buySignal and newBrick and barstate.isconfirmed and inTradingHours//买入条件
exitLong = (sellSignal and newBrick and barstate.isconfirmed) or timeToClose//卖出条件
// 执行交易
if (enterLong)
strategy.entry("Long", strategy.long)//开仓做多
if (exitLong)
strategy.close("Long")//平仓
// --- 绘图 ---
color brickColor = direction == 1 ? color.green : direction == -1 ? color.red : color.gray//根据方向设置砖块颜色
plot(lastClose, "Renko Close", brickColor, 2, plot.style_linebr)//绘制Renko收盘价
// 如果启用,绘制影线
plot(showWicks ? wickHigh : na, "High", color.new(brickColor, 70), 1, plot.style_circles)//绘制上影线
plot(showWicks ? wickLow : na, "Low", color.new(brickColor, 70), 1, plot.style_circles)//绘制下影线
// 绘制交易时间背景
bgcolor(inTradingHours ? color.new(color.blue, 90) : na)//在交易时间内显示浅蓝色背景