High Beta Momentum Engine

durairaj1936 · study · 195 行 · 点赞 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/
// © durairaj1936
 
//@version=6
indicator("High Beta Momentum Engine", overlay=true, max_labels_count=500)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// INPUTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
fastLen      = input.int(20,  "Fast EMA", minval=1)
slowLen      = input.int(50,  "Slow EMA", minval=2)
 
rsiLen       = input.int(14,  "RSI Length", minval=2)
rsiBuy       = input.float(55, "RSI Buy Level")
rsiSell      = input.float(45, "RSI Sell Level")
 
atrLen       = input.int(14,  "ATR Length", minval=2)
atrAvgLen    = input.int(50,  "ATR Average Length", minval=5)
 
volLen       = input.int(20,  "Volume Average", minval=2)
rvolMin      = input.float(1.5, "Minimum RVOL", step=0.1)
 
breakoutLen  = input.int(20, "Breakout Lookback", minval=2)
 
benchmark    = input.symbol("AMEX:SPY", "Benchmark")
 
cooldownBars = input.int(10, "Signal Cooldown", minval=0)
 
showEMA      = input.bool(false, "Show EMAs")
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CORE CALCULATIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
// Trend
emaFast = ta.ema(close, fastLen)
emaSlow = ta.ema(close, slowLen)
 
// Momentum
rsi = ta.rsi(close, rsiLen)
 
// Volatility
atr = ta.atr(atrLen)
atrAvg = ta.sma(atr, atrAvgLen)
 
volAvg = ta.sma(volume, volLen)
rvol = volAvg > 0 ? volume / volAvg : 0
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BENCHMARK / RELATIVE STRENGTH
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
benchClose = request.security(
     benchmark,
     timeframe.period,
     close,
     lookahead=barmerge.lookahead_off)
 
stockReturn = close / close[20] - 1
benchReturn = benchClose / benchClose[20] - 1
 
relativeStrength = stockReturn > benchReturn
 
relativeWeakness = stockReturn < benchReturn
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// VOLATILITY EXPANSION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
volatilityExpansion = atr > atrAvg
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BREAKOUT / BREAKDOWN
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
// Previous resistance/support.
// [1] prevents using the current candle's high/low.
previousHigh = ta.highest(high, breakoutLen)[1]
previousLow  = ta.lowest(low, breakoutLen)[1]
 
bullBreakout = close > previousHigh
bearBreakdown = close < previousLow
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// TREND
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullTrend =
     close > emaFast and
     emaFast > emaSlow and
     emaFast > emaFast[1]
 
bearTrend =
     close < emaFast and
     emaFast < emaSlow and
     emaFast < emaFast[1]
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// MOMENTUM
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullMomentum =
     rsi > rsiBuy and
     rsi > rsi[1]
 
bearMomentum =
     rsi < rsiSell and
     rsi < rsi[1]
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// VOLUME CONFIRMATION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
strongVolume = rvol >= rvolMin
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SIGNAL CONDITIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
rawBuy =
     bullTrend and
     bullMomentum and
     relativeStrength and
     strongVolume and
     volatilityExpansion and
     bullBreakout
 
rawSell =
     bearTrend and
     bearMomentum and
     relativeWeakness and
     strongVolume and
     volatilityExpansion and
     bearBreakdown
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// COOLDOWN
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var int lastSignalBar = na
 
canSignal =
     na(lastSignalBar) or
     bar_index - lastSignalBar > cooldownBars
 
buySignal =
     rawBuy and
     canSignal
 
sellSignal =
     rawSell and
     canSignal
 
if buySignal or sellSignal
    lastSignalBar := bar_index
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// PLOTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
// Hidden by default
plot(showEMA ? emaFast : na, "20 EMA")
plot(showEMA ? emaSlow : na, "50 EMA")
 
// BUY
plotshape(
     buySignal,
     title="BUY",
     style=shape.labelup,
     location=location.belowbar,
     text="BUY",
     size=size.small)
 
// SELL
plotshape(
     sellSignal,
     title="SELL",
     style=shape.labeldown,
     location=location.abovebar,
     text="SELL",
     size=size.small)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
alertcondition(
     buySignal,
     title="High Beta BUY",
     message="High Beta Momentum Engine: BUY signal")
 
alertcondition(
     sellSignal,
     title="High Beta SELL",
     message="High Beta Momentum Engine: SELL signal")

← 返回列表