TASC 2026.10 A Low-Risk ETF-Trading Strategy

PineCodersTASC · study · 154 行 · 点赞 588 · TradingView 原页

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

Pine Script

//  TASC Issue: October 2026
//     Article: Selecting Strong ETFs While Avoiding
//               Sharp Overbought Reversals
//              A Low-Risk ETF Trading Strategy
//  Article By: Markos Katsanos
//    Language: TradingView's Pine Script™ v6
// Provided By: PineCoders, for tradingview.com
 
// Use this watchlist with the Pine Screener to 
// show signals across the universe of ETFs for
// this strategy.
// Watchlist:
// https://www.tradingview.com/watchlists/341036576/
// Pine Screener:
// https://www.tradingview.com/pine-screener/
 
//@version=6
TITLE = "TASC 2026.10 A Low-Risk ETF-Trading Strategy"
SHORTTITLE = "LRETF-Strat"
indicator(TITLE, SHORTTITLE)
 
//#region Functions
 
// 2023.12
// @function Custom Relative Strength Indicator (RSMK)
// @param base     Input time series
// @param im       Reference time series
// @param bars     N bars for RS calculation
// @param sk       Smoothing constant
// @returns        Relative Strength
RS (float _base, float _im, int _bars, int _sk) =>
    float r12 = _base/_im
    float rs1 = (math.log(r12) 
         - math.log(nz(r12[_bars], 0.0)))
    ta.ema(rs1, _sk)*100.0
 
//#endregion
//#region Inputs
 
//Calculation Parameters
G1 = "RS Parameters"
int rsBars = input.int(35, "RSMK length", group = G1)  
int rsiBars = input.int(10, "RSI length", group = G1)
 
//Entry Parameters
G2 = "Entry/Exit Parameters"
int mar = input.int(50, "RS MA length", group = G2)
float rsCrit = input.float(3.0, "RS entry level", group = G2)
int maB = 4 //input.int(4, "Smoothing Constant", 1, 50)
int minVol = input.int(100000, "Minimum volume", 
     minval = 0, maxval = 1000000, group = G2)
 
float rsiOS = input.float(35.0, "RSI oversold", group = G2)
int maBars = input.int(15, "MA bars", group = G2)
float corMin = input.float(0.6, "Minimum correlation", group = G2)
 
int timeExit = input.int(30, "Rebalance period", group = G2) 
 
string bSym = input.symbol("AMEX:SPY", "Benchmark symbol")
 
//#endregion
//#region Calculations
 
float bench = 
     request.security(bSym, timeframe.period, close)
 
float cor = ta.correlation(close, bench, 100)
float rsmk = RS(close, bench, rsBars, maB)
float mars = ta.sma(rsmk, mar)
float hhRsmk = ta.highest(rsmk, 4)
float rocInd = (ta.change(bench, 6)/bench[6])*100
float rsi = ta.rsi(close, rsiBars)
float llRsi = ta.lowest(rsi, 20)
float ema5 = ta.ema(close, 5) 
float sma5 = ta.sma(close, maBars)
 
//#endregion
//#region Conditions
 
bool gotVol = ta.sma(volume, 5) > minVol
bool rsmkSignal = (rsmk > mars and rsmk > rsCrit and 
     rsmk == hhRsmk and rsmk < 25)
 
bool rocSignal = ((rocInd > -6 and cor > corMin) or 
     (rocInd < -6 and cor < -corMin))
 
bool rsiSignal = llRsi < rsiOS and rsi > rsi[3]
bool momSignal = ema5 > sma5[5]
 
var int pos = 0
var float ep = close
var int eb = bar_index
 
bool isBuy = (gotVol and rsmkSignal and 
     rocSignal and rsiSignal and 
     momSignal and pos == 0)
 
bool isSell = rsmk < -rsCrit and cor > 0.8 and pos == 1
bool perExit = pos == 1 and close >= ep*1.25
bool reBal = pos == 1 and bar_index - eb >= timeExit
 
exit = isSell or perExit or reBal
 
pos := isBuy?1:(exit?0:pos)
ep := isBuy?close:ep
eb := isBuy?bar_index:eb
 
posProf = pos == 1 ? (close - ep)/ep*100 : na
 
//#endregion
//#region Plots
 
e = plot(pos == 1 or  pos[1] == 1?ep:na, "Entry Price",
     color.yellow, style = plot.style_linebr, 
     force_overlay = true, 
     linestyle = plot.linestyle_dotted)
 
c = plot(close, "Close plot for fill", 
     display = display.none, force_overlay = true, 
     editable = false)
 
 
posCol = (close[1] > ep ? 
     color.new(color.teal,80) : 
     color.new(color.red,80)) 
 
plot(posProf, "Position Performance", posCol, 
     display = display.all - display.pane, 
     format = format.percent)
 
fill(c,e, posCol, "Position Colors")
 
plot(rsmk, "RSMK", color = rsmk>0?color.lime:color.red)
 
plot(mars, "RS MA", color.blue, 
     linestyle = plot.linestyle_dashed)
 
hline(0, linestyle = hline.style_solid)
 
plotshape(isBuy?1:na, "Enter", shape.triangleup, 
     location.belowbar, color.green, 
     size = size.small, force_overlay = true)
 
plotshape(exit?-1:na, "Exit", shape.xcross, 
     location.abovebar, color.red, 
     size = size.small, force_overlay = true)
 
//#endregion
//#region Alerts
 
alertcondition(isBuy, "Enter Alert")
alertcondition(exit, "Exit Alert")
 
//#endregion

← 返回列表