技术需求:在Pine Script中实现24小时交易时段内XX:05与XX:35时刻5分钟K线的高亮显示
Alright, let's figure out how to make those specific 5-minute candles stand out exactly as you need. I'll use Pine Script (the go-to for TradingView, which handles 24/7 trading sessions smoothly) as an example, since it's super accessible for this kind of customization.
First, we need to filter for only the candles that end at XX:05 and XX:35. Since we're working with 5-minute bars, each candle's end time will have a minute value of either 5 or 35. We can grab the minute part of the candle's timestamp to check this.
Next, we'll distinguish between up candles (where the closing price is higher than the opening price) and down candles (closing price lower than opening price).
Finally, we'll apply green to target up candles and red to target down candles, leaving all other candles with their default appearance.
Here's the full script you can drop right into TradingView:
//@version=5 indicator("Highlight XX:05 & XX:35 Candles", overlay=true) // Define the minutes we want to target target_minutes = [5, 35] // Check if current candle ends at either target minute is_target_candle = ta.minute(time) == target_minutes[0] or ta.minute(time) == target_minutes[1] // Identify up and down candles is_up_candle = close > open is_down_candle = close < open // Apply color only to our target candles barcolor( is_target_candle and is_up_candle ? color.green : is_target_candle and is_down_candle ? color.red : na // Leave other candles as default )
Quick Breakdown of the Code:
ta.minute(time)pulls the minute value from the candle's end timestamp. We compare this to our target minutes (5 and 35) to flag the right candles.is_up_candleandis_down_candledo exactly what they sound like—check if the candle is bullish or bearish.barcolor()sets the candle color: green for target up candles, red for target down candles, andna(no color) for everything else, so your other candles stay unchanged.
If you're using a different platform (like MT4/MT5 with MQL), the core logic stays the same:
- Extract the minute from the candle's time using
TimeMinute() - Check if it's 5 or 35
- Compare close and open prices
- Use
SetBarColor()to apply green/red to matching candles
内容的提问来源于stack exchange,提问作者canerbanana

