Rally Finder

rikyu04 · study · 50 行 · 点赞 8 · 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/MPL/2.0/
// © rikyu04
 
//@version=6
indicator(title="Rally Finder", overlay=true, max_labels_count=500, max_lines_count=500)
 
// ==========================================
// Settings
// ==========================================
multInput   = input.float(5.0, "Rally Multiplier (x)", minval=1.1, step=0.5, tooltip="Mark when price reaches this multiple of the base (lowest close).")
targetInput = input.string("High", "Target Price", options=["High", "Close"], tooltip="High: includes wicks. Close: only counts if the bar closes at or above the target.")
showBase    = input.bool(true, "Show Base Label")
showLine    = input.bool(true, "Draw Line from Base to Target")
 
// ==========================================
// Base tracking (lowest close since the last signal)
// ==========================================
var float baseClose    = na
var int   baseCloseBar = na
 
// Update the base whenever a new lower close appears
if na(baseClose) or close < baseClose
    baseClose    := close
    baseCloseBar := bar_index
 
// ==========================================
// Rally detection
// ==========================================
float targetPrice = targetInput == "High" ? high : close
float ratio       = targetPrice / baseClose
bool  rallyHit    = not na(baseClose) and baseClose > 0 and ratio >= multInput
 
if rallyHit
    // Mark the target bar with the actual multiple reached
    label.new(bar_index, targetPrice, "🔥 x" + str.tostring(ratio, "#.#"), color=color.new(color.orange, 30), textcolor=color.white, style=label.style_label_down, size=size.normal)
    
    // Mark the base (lowest close)
    if showBase
        label.new(baseCloseBar, baseClose, "BASE", color=color.new(color.teal, 30), textcolor=color.white, style=label.style_label_up, size=size.small)
    
    // Connect base to target
    if showLine
        line.new(baseCloseBar, baseClose, bar_index, targetPrice, color=color.orange, style=line.style_dashed, width=1)
    
    // Reset: start tracking a new base from this bar's close
    baseClose    := close
    baseCloseBar := bar_index
 
// Alert
alertcondition(rallyHit, title="Rally Hit", message="{{ticker}}: price reached the rally multiple from its base. Close: {{close}}")

← 返回列表