Açıklamalar
- Bollinger Bands: Fiyatın volatilitesini ölçer ve potansiyel alım/satım sinyalleri üretir.
- TNX (10-Year Treasury Yield): 10 yıllık ABD Hazine tahvili faiz oranını temsil eder; faiz oranları ile REIT ETF’leri arasındaki ilişkiyi analiz eder.
- Donchian Channel: Fiyatın belirli bir dönem içindeki en yüksek ve en düşük seviyelerini gösterir; trend yönünü belirlemede kullanılır.
- Correlation (CORt ve CORs): Fiyat ile TNX ve SPY arasındaki korelasyonu ölçer; düşük korelasyon alım sinyali oluşturabilir.
- Stochastic Oscillator: Aşırı alım veya aşırı satım koşullarını belirler; potansiyel dönüş noktalarını işaret eder.
- ATR (Average True Range): Volatiliteyi ölçer; stop loss seviyelerinin belirlenmesinde kullanılır.
Kullanım
- Zaman Dilimi: Strateji, haftalık (weekly) zaman diliminde çalışacak şekilde tasarlanmıştır.
- Uygulama: TradingView platformunda, bu kodu Pine Script Editor’e yapıştırarak stratejiyi uygulayabilirsiniz.
- Veri Kaynağı: SPY (S&P 500 ETF) ve TNX (
//@version=5
string it = ‘TASC 2024.06 REIT ETF Trading System’
string st = ‘REIT TS’
strategy(it, st, true)
// — Inputs —
int iBBlen = input.int(15, ‘Bollinger Bands Length’)
float iBBmul = input.float(2.0, ‘Bollinger Bands Multiplier’)
int iTNXlen = input.int(25, ‘Lookback Period for TNX Index’)
int iTNXper = input.int(15, ‘Min TNX Change, %’)
int iDClen = input.int(30, ‘Donchian Channel Length’)
float iCORmax = input.float(0.3, ‘Max Correlation for Buy Signal’)
float iYLDmin = input.float(2.0, ‘Min Yield (TNX/10)’)
float iATRstp = input.float(1.5, ‘ATR Stop’)
int iMAXlos = input.int(8, ‘Stop Loss, %’)
// — Helper Functions —
NotAtLoss(float src, float limit) =>
src < ((1.0 – iMAXlos / 100.0) * limit)
// — Calculations —
if not timeframe.isweekly
string er0 = ‘The script should be applied on a WEEKLY chart of any REIT ETF.’
runtime.error(er0)
// Reference indices (SPY and TNX)
float spy = request.security(‘SPY’, timeframe.period, close, barmerge.gaps_on, barmerge.lookahead_off)
float tnx = request.security(‘TNX’, timeframe.period, close, barmerge.gaps_on, barmerge.lookahead_off)
// Treasury Yield, Stochastic, ATR
float yld = tnx / 10.0
float stoch = ta.sma(ta.stoch(close, high, low, 10), 3)
float atr15 = ta.atr(15)
// HH & LL of TNX
float TNXll = ta.lowest(tnx, iTNXlen)
float TNXhh = ta.highest(tnx, iTNXlen)
float TNXup = ((tnx – TNXll) / (TNXll + 0.001)) * 100.0
float TNXdn = ((tnx – TNXhh) / (TNXhh + 0.001)) * 100.0
// HH & LL of ETF
int LLbars = bar_index >= 100 ? 100 : bar_index + 1
float ll = ta.lowest(low, LLbars)
float PERCup = (close – ll) / (ll + 0.001) * 100.0
float DCupper = ta.highest(close, iDClen)[1]
// Correlations
float CORt = ta.correlation(close, tnx, 20)
float CORs = ta.correlation(close, spy, 20)
float BBlower = ta.sma(close, iBBlen) – iBBmul * ta.stdev(close, iBBlen)
bool isStop = close < ta.sma(close, 30) and NotAtLoss(close, ta.highest(close, 2)) and NotAtLoss(spy, spy[1]) or CORs < 0
// Trade Signals
bool BuyBB = (low < BBlower and close > BBlower + 0.2 * atr15) and ((TNXdn < -iTNXper and CORt < iCORmax) or yld < iYLDmin) and close > hl2 and not isStop
bool BuyTrend = close > DCupper and spy > ta.sma(spy, 20) and (ta.highest(tnx, iTNXlen) > 10.0 or CORt > iCORmax or yld < iYLDmin)
// Stop Loss
bool Sell1 = (TNXup > iTNXper or (yld > 4.0 and TNXup > 0.0)) and close < ta.highest(close, 5) – iATRstp * atr15 and not BuyBB bool Stop0 = close < ta.sma(close, 30) and NotAtLoss(close, close[1]) and NotAtLoss(spy, spy[1]) or CORs < 0 bool SellOB = PERCup > 50.0 and close < ta.highest(high, 3) – iATRstp * atr15 and ta.highest(stoch, 3) > 90
// Execution
switch
BuyBB =>
strategy.entry(“BUY BB”, strategy.long)
BuyTrend =>
strategy.entry(“BUY Trend”, strategy.long)
Sell1 =>
strategy.close_all(‘STOP Trail’)
SellOB =>
strategy.close_all(‘STOP OB’)
Stop0 =>
strategy.close_all(‘STOP Stop’)
Yorum bırakın