Previous Candle Levels - Anchored

FAFO_Trades · study · 68 行 · 点赞 11 · TradingView 原页

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

Pine Script

//@version=6
indicator("Previous Candle Levels - Anchored", overlay=true, max_lines_count=3)
 
// LINE SETTINGS
groupLines = "Line Settings"
 
// High line
highColor = input.color(color.white, "High Color", group=groupLines)
highStyle = input.string("Dotted", "High Line Type", options=["Solid", "Dashed", "Dotted"], group=groupLines)
 
// Midpoint line
midColor = input.color(color.yellow, "50% Color", group=groupLines)
midStyle = input.string("Dotted", "50% Line Type", options=["Solid", "Dashed", "Dotted"], group=groupLines)
 
// Low line
lowColor = input.color(color.white, "Low Color", group=groupLines)
lowStyle = input.string("Dotted", "Low Line Type", options=["Solid", "Dashed", "Dotted"], group=groupLines)
 
// Thickness
lineWidth = input.int(2, "Line Width", minval=1, maxval=5, group=groupLines)
 
// Convert line type
getStyle(style) =>
    switch style
        "Solid" => line.style_solid
        "Dashed" => line.style_dashed
        => line.style_dotted
 
// PREVIOUS CANDLE LEVELS
prevHigh = high[1]
prevLow = low[1]
midpoint = (prevHigh + prevLow) / 2
 
// Anchor to previous candle
anchorTime = time[1]
 
// Extend 5 minutes
fiveMinutes = 5 * 60 * 1000
endTime = anchorTime + fiveMinutes
 
// LINES
var line highLine = na
var line midLine = na
var line lowLine = na
 
if barstate.islast and not na(prevHigh)
    if na(highLine)
        highLine := line.new(anchorTime, prevHigh, endTime, prevHigh, xloc=xloc.bar_time, color=highColor, style=getStyle(highStyle), width=lineWidth)
        midLine := line.new(anchorTime, midpoint, endTime, midpoint, xloc=xloc.bar_time, color=midColor, style=getStyle(midStyle), width=lineWidth)
        lowLine := line.new(anchorTime, prevLow, endTime, prevLow, xloc=xloc.bar_time, color=lowColor, style=getStyle(lowStyle), width=lineWidth)
    else
        line.set_xy1(highLine, anchorTime, prevHigh)
        line.set_xy2(highLine, endTime, prevHigh)
        line.set_color(highLine, highColor)
        line.set_style(highLine, getStyle(highStyle))
        line.set_width(highLine, lineWidth)
 
        line.set_xy1(midLine, anchorTime, midpoint)
        line.set_xy2(midLine, endTime, midpoint)
        line.set_color(midLine, midColor)
        line.set_style(midLine, getStyle(midStyle))
        line.set_width(midLine, lineWidth)
 
        line.set_xy1(lowLine, anchorTime, prevLow)
        line.set_xy2(lowLine, endTime, prevLow)
        line.set_color(lowLine, lowColor)
        line.set_style(lowLine, getStyle(lowStyle))
        line.set_width(lowLine, lineWidth)

← 返回列表