PROTECTED SOURCE SCRIPT

Universal Trend Predictor

33
//version=5
indicator("Universal Trend Predictor", overlay=true, max_labels_count=500)

// === INPUTS ===
len_trend = input.int(50, "Trend Length (regression)", minval=10, maxval=200)
len_mom = input.int(14, "Momentum Length", minval=5, maxval=50)
len_vol = input.int(20, "Volume SMA Length", minval=5, maxval=100)
correlation_weight = input.float(0.5, "Correlation Weight (0-1)", minval=0, maxval=1)

// === TREND LINE (Linear Regression) ===
reg = ta.linreg(close, len_trend, 0)
reg_slope = ta.linreg(close, len_trend, 0) - ta.linreg(close, len_trend, 1)

// === MOMENTUM ===
mom = ta.mom(close, len_mom)

// === VOLUME ===
vol_sma = ta.sma(volume, len_vol)
vol_factor = volume / vol_sma

// === CORRELATION ASSETS ===
spx = request.security("SPX", timeframe.period, close)
dxy = request.security("DXY", timeframe.period, close)
xau = request.security("XAUUSD", timeframe.period, close)

// === CORRELATION LOGIC ===
spx_mom = ta.mom(spx, len_mom)
dxy_mom = ta.mom(dxy, len_mom)
xau_mom = ta.mom(xau, len_mom)

// Корреляция: усиливаем сигнал, если BTC и SPX растут, ослабляем если DXY растет
correlation_score = 0.0
correlation_score := (mom > 0 and spx_mom > 0 ? 1 : 0) - (mom > 0 and dxy_mom > 0 ? 1 : 0) + (mom > 0 and xau_mom > 0 ? 0.5 : 0)
correlation_score := correlation_score * correlation_weight

// === SIGNAL LOGIC ===
trend_up = reg_slope > 0
trend_down = reg_slope < 0
strong_mom = math.abs(mom) > ta.stdev(close, len_mom) * 0.5
high_vol = vol_factor > 1

buy_signal = trend_up and mom > 0 and strong_mom and high_vol and correlation_score >= 0
sell_signal = trend_down and mom < 0 and strong_mom and high_vol and correlation_score <= 0

// === ПАРАМЕТРЫ ДЛЯ ПРОГНОЗА ===
months_forward = 3
bars_per_month = timeframe.isintraday ? math.round(30 * 24 * 60 / timeframe.multiplier) :
timeframe.isdaily ? 30 :
timeframe.isweekly ? 4 :
30
bars_forward = math.min(months_forward * bars_per_month, 500) // TradingView лимит

// === ОГРАНИЧЕНИЕ ЧАСТОТЫ СИГНАЛОВ ===
var float last_buy_bar = na
var float last_sell_bar = na
can_buy = na(last_buy_bar) or (bar_index - last_buy_bar >= 15)
can_sell = na(last_sell_bar) or (bar_index - last_sell_bar >= 15)

buy_signal_final = buy_signal and can_buy
sell_signal_final = sell_signal and can_sell
if buy_signal_final
last_buy_bar := bar_index
if sell_signal_final
last_sell_bar := bar_index

// === ВЫДЕЛЕНИЕ СИЛЬНЫХ СИГНАЛОВ ===
strong_signal = strong_mom and math.abs(reg_slope) > ta.stdev(close, len_trend) * 0.5

// === VISUALIZATION ===
// Trend line (основная)
plot(reg, color=trend_up ? color.green : color.red, linewidth=2, title="Trend Line")

// Прогноз трендовой линии вперёд
reg_future = reg + reg_slope * bars_forward
line.new(x1=bar_index, y1=reg, x2=bar_index + bars_forward, y2=reg_future, color=color.new(color.blue, 0), width=2, extend=extend.none)

// Buy/Sell labels
plotshape(buy_signal_final and not strong_signal, style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.small, text="BUY", title="Buy Signal")
plotshape(buy_signal_final and strong_signal, style=shape.labelup, location=location.belowbar, color=color.new(color.lime, 0), size=size.large, text="BUY", title="Strong Buy Signal")
plotshape(sell_signal_final and not strong_signal, style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), size=size.small, text="SELL", title="Sell Signal")
plotshape(sell_signal_final and strong_signal, style=shape.labeldown, location=location.abovebar, color=color.new(color.fuchsia, 0), size=size.large, text="SELL", title="Strong Sell Signal")

// Trend direction forecast (arrow)
plotarrow(trend_up ? 1 : trend_down ? -1 : na, colorup=color.green, colordown=color.red, offset=0, title="Trend Forecast Arrow")

// === ALERTS ===
alertcondition(buy_signal, title="Buy Alert", message="Universal Trend Predictor: BUY signal!")
alertcondition(sell_signal, title="Sell Alert", message="Universal Trend Predictor: SELL signal!")

// === END ===

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。