You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

技术需求:在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.

Step 1: Pinpoint the Target Candles

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.

Step 2: Label Up vs. Down Candles

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).

Step 3: Apply the Highlighting

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_candle and is_down_candle do 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, and na (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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 17:32:29