本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
indicator("Austin's Range Filter with Trade Signals", overlay=true)
// User Inputs for customization
len = input.int(50, title="Range Filter Length", minval=1) // Length of the range filter
rangeMultiplier = input.float(3.0, title="Range Multiplier", minval=0.1) // Multiplier for the range
emaLength = input.int(50, title="EMA Length", minval=1) // Length of the EMA
// User inputs to toggle visibility of the lines
showCombinedBand = input.bool(true, title="Show Combined Band (Purple Line)")
showEMA = input.bool(true, title="Show EMA (Blue Line)")
// Calculate range (renaming range to rangeVal)
highs = ta.highest(high, len)
lows = ta.lowest(low, len)
rangeVal = (highs - lows) * rangeMultiplier
// Calculate the middle line (combined upper and lower band)
middleLine = ta.sma(close, len) // SMA of the close price as the center line
rangeUpper = middleLine + rangeVal
rangeLower = middleLine - rangeVal
averageBand = (rangeUpper + rangeLower) / 2 // This is essentially the middle of both bands
// Plot the combined band (single line) based on user input
plot(showCombinedBand ? averageBand : na, color=color.purple, linewidth=2, title="Combined Band")
// Plot background colors for long/short conditions
longCondition = close > rangeUpper
shortCondition = close < rangeLower
bgcolor(longCondition ? color.new(color.green, 80) : na)
bgcolor(shortCondition ? color.new(color.red, 80) : na)
// Add user-modifiable EMA
emaLine = ta.ema(close, emaLength)
// Plot the EMA based on user input
plot(showEMA ? emaLine : na, color=color.blue, linewidth=2, title="EMA")
// Buy and Sell Conditions based on EMA crossover
buySignal = ta.crossover(close, emaLine) // Buy when price crosses above EMA
sellSignal = ta.crossunder(close, emaLine) // Sell when price crosses below EMA
// Plot Buy and Sell Signals for visual confirmation
plotshape(series=buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, size=size.small, text="BUY")
plotshape(series=sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, size=size.small, text="SELL")
// Define the current trend color: Green if price is above EMA, Red if below
currentTrendColor = close > emaLine ? color.green : color.red
// Plot the trend line based on the buy/sell condition
plot(close, color=currentTrendColor, linewidth=2, title="Trend Line")
// Alert conditions for Buy and Sell
alertcondition(buySignal, title="Buy Signal Alert", message="Price crossed above EMA - Buy Signal")
alertcondition(sellSignal, title="Sell Signal Alert", message="Price crossed below EMA - Sell Signal")