Support & Resistance + PDH/PDL + EMA/MACD/RSI/ADX Table

TrendRiderPro · study · 81 行 · 点赞 2,362 · TradingView 原页

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

Pine Script

//@version=5
indicator("Support & Resistance - Solid Long Boxes", overlay = true)
 
// ────────────────────────────────────────────────
// Inputs
// ────────────────────────────────────────────────
leftBars   = input.int(5,  "Pivot Left Bars",  minval = 1)
rightBars  = input.int(5,  "Pivot Right Bars", minval = 1)
maxLevels  = input.int(5,  "Max Support/Resistance Levels", minval = 1, maxval = 20)
lineWidth  = input.int(1,  "Line Width (1 = thin)", minval = 1, maxval = 5)
 
// ────────────────────────────────────────────────
// Detect Pivots
// ────────────────────────────────────────────────
pHigh = ta.pivothigh(high, leftBars, rightBars)
pLow  = ta.pivotlow(low,  leftBars, rightBars)
 
// ────────────────────────────────────────────────
// Arrays to store recent levels
// ────────────────────────────────────────────────
var line[] resLines = array.new_line(0)
var line[] supLines = array.new_line(0)
 
// ────────────────────────────────────────────────
// Add new resistance level
// ────────────────────────────────────────────────
if not na(pHigh)
    // Create new solid horizontal line
    newLine = line.new(
         x1 = bar_index[rightBars],
         y1 = pHigh,
         x2 = bar_index + 200,   // long extension to the right
         y2 = pHigh,
         color = color.new(color.red, 40),    // semi-transparent red
         width = lineWidth,
         style = line.style_solid)           // solid line (no dots/dashes)
    
    array.push(resLines, newLine)
    
    // Limit to maxLevels (remove oldest)
    if array.size(resLines) > maxLevels
        oldLine = array.shift(resLines)
        line.delete(oldLine)
 
// ────────────────────────────────────────────────
// Add new support level
// ────────────────────────────────────────────────
if not na(pLow)
    newLine = line.new(
         x1 = bar_index[rightBars],
         y1 = pLow,
         x2 = bar_index + 200,   // long extension
         y2 = pLow,
         color = color.new(color.green, 40),  // semi-transparent green
         width = lineWidth,
         style = line.style_solid)
    
    array.push(supLines, newLine)
    
    if array.size(supLines) > maxLevels
        oldLine = array.shift(supLines)
        line.delete(oldLine)
 
// ────────────────────────────────────────────────
// Optional labels for last pivot
// ────────────────────────────────────────────────
if not na(pHigh)
    label.new(bar_index[rightBars], pHigh, 
         text = "R", 
         color = color.new(color.red, 60), 
         textcolor = color.white, 
         style = label.style_label_down,
         size = size.small)
 
if not na(pLow)
    label.new(bar_index[rightBars], pLow, 
         text = "S", 
         color = color.new(color.green, 60), 
         textcolor = color.white, 
         style = label.style_label_up,
         size = size.small)

← 返回列表