OPEN-SOURCE SCRIPT

TH Uptrend Consolidation

//version=5
indicator("Custom Buy Signal with Time Filter", overlay=true)

// Inputs for RSI
rsi_length = input.int(14, title="RSI Length")
rsi_source = input.source(close, title="RSI Source")
rsi_lower = input.float(50, title="RSI Lower Bound")
rsi_upper = input.float(65, title="RSI Upper Bound")

// Inputs for EMA
ema_short_length = input.int(20, title="EMA Short Length (EMA20)")
ema_long_length = input.int(50, title="EMA Long Length (EMA50)")

// Inputs for Time Filter
signal_cooldown = input.int(14, title="Cooldown Period (Days)")

// Calculate RSI and EMAs
rsi_value = ta.rsi(rsi_source, rsi_length)
ema20 = ta.ema(close, ema_short_length)
ema50 = ta.ema(close, ema_long_length)

// Calculate Price Distance from EMA20
price_distance_percent = math.abs(close - ema20) / ema20 * 100

// Conditions
rsi_condition = (rsi_value >= rsi_lower and rsi_value <= rsi_upper)
ema_condition = ema20 > ema50
price_condition = close > ema20
distance_condition = price_distance_percent <= 5

// Final Buy Signal Conditions
buy_signal_raw = rsi_condition and ema_condition and price_condition and distance_condition

// Time Filter Logic
var float last_signal_time = na // Persistent variable for last signal time
is_cooldown_over = na(last_signal_time) or (time - last_signal_time > signal_cooldown * 86400000) // 86400000 ms in a day
buy_signal = buy_signal_raw and is_cooldown_over

if buy_signal
last_signal_time := time // Update last signal time when a new signal is generated

// Plot EMAs
plot(ema20, color=color.blue, title="EMA20")
plot(ema50, color=color.orange, title="EMA50")

// Highlight Buy Signals
plotshape(series=buy_signal, style=shape.labelup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
Chart patternsMoving Averages

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?

免責聲明