Dino Candle-Range BO

DinoTrading · study · 88 行 · 点赞 11 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org
// © DinoTrading
 
 //@version=6
indicator("Dino Candle-Range BO", overlay=true, max_lines_count=10)
 
// ==========================================
// 1. SETTINGS
// ==========================================
string G_STYLE = "Appearance"
 
color high_color = input.color(color.blue, "High Line Color", group=G_STYLE)
color low_color = input.color(color.blue, "Low Line Color", group=G_STYLE)
int line_width = input.int(2, "Line Width", minval=1, maxval=5, group=G_STYLE)
 
// ==========================================
// 2. STATE MANAGEMENT
// ==========================================
// 0 = Searching for a reference candle
// 1 = Monitoring the active candle range
// 2 = Breakout confirmed, waiting for a new range
 
var int state = 0
 
var float mother_high = na
var float mother_low = na
 
var line high_line = na
var line low_line = na
 
// ==========================================
// 3. CANDLE RANGE LOGIC
// ==========================================
if barstate.isconfirmed and not na(high[1])
 
    // Does the candle close inside the previous candle's range?
    bool inside = close > low[1] and close < high[1]
 
    // STATE 1: MONITOR ACTIVE RANGE
    if state == 1
        if close > mother_high or close < mother_low
            // Close-based breakout confirmed
            state := 2
 
    // STATE 0 OR 2:
    // Establish a new range only after a valid inside close
    if state == 0 or state == 2
        if inside
 
            // Completely remove the previous range lines
            if not na(high_line)
                line.delete(high_line)
            if not na(low_line)
                line.delete(low_line)
 
            // Previous candle becomes the new reference candle
            mother_high := high[1]
            mother_low := low[1]
 
            // Draw the new range levels
            high_line := line.new(
                 x1=time[1],
                 y1=mother_high,
                 x2=time_close,
                 y2=mother_high,
                 xloc=xloc.bar_time,
                 color=high_color,
                 width=line_width
                 )
 
            low_line := line.new(
                 x1=time[1],
                 y1=mother_low,
                 x2=time_close,
                 y2=mother_low,
                 xloc=xloc.bar_time,
                 color=low_color,
                 width=line_width
                 )
 
            state := 1
 
// ==========================================
// 4. EXTEND ACTIVE RANGE LINES
// ==========================================
if not na(high_line)
    line.set_x2(high_line, time_close)
    line.set_x2(low_line, time_close)

← 返回列表