Use Plot Instead of Label: //@version=5 indicator("Multi Time Frame Trend Detector",…
- User
Use Plot Instead of Label: //@version=5 indicator("Multi Time Frame Trend Detector", overlay=true)
// === User Inputs ===
// Time Frame Inputs higher_tf = input.timeframe("D", "Higher Time Frame") intermediate_tf = input.timeframe("60", "Intermediate Time Frame")
// Pivot Parameters pivot_left = input.int(5, "Pivot Left Bars", minval=1) pivot_right = input.int(5, "Pivot Right Bars", minval=1) num_pivots_to_show = input.int(5, "Number of Recent Pivots to Show", minval=1)
// Moving Average Length ma_length = input.int(21, "MA Length")
// === Time Frame Data Retrieval ===
// Higher Time Frame Data htf_high = request.security(syminfo.tickerid, higher_tf, high) htf_low = request.security(syminfo.tickerid, higher_tf, low) htf_close = request.security(syminfo.tickerid, higher_tf, close)
// Intermediate Time Frame Data itf_high = request.security(syminfo.tickerid, intermediate_tf, high) itf_low = request.security(syminfo.tickerid, intermediate_tf, low) itf_close = request.security(syminfo.tickerid, intermediate_tf, close)
// === Pivot Point Detection ===
// Higher Time Frame Pivots htf_pivot_high = ta.pivothigh(htf_high, pivot_left, pivot_right) htf_pivot_low = ta.pivotlow(htf_low, pivot_left, pivot_right)
// Intermediate Time Frame Pivots itf_pivot_high = ta.pivothigh(itf_high, pivot_left, pivot_right) itf_pivot_low = ta.pivotlow(itf_low, pivot_left, pivot_right)
// Shift pivots back by pivot_right bars htf_pivot_high_shifted = htf_pivot_high[pivot_right] htf_pivot_low_shifted = htf_pivot_low[pivot_right] htf_close_shifted = htf_close[pivot_right]
itf_pivot_high_shifted = itf_pivot_high[pivot_right] itf_pivot_low_shifted = itf_pivot_low[pivot_right] itf_close_shifted = itf_close[pivot_right]
// === Moving Averages ===
htf_ma = ta.sma(htf_close, ma_length) htf_ma_shifted = htf_ma[pivot_right]
itf_ma = ta.sma(itf_close, ma_length) itf_ma_shifted = itf_ma[pivot_right]
// === Trend Determination ===
// Higher Time Frame Trend var string htf_trend = na if not na(htf_pivot_high_shifted) htf_trend := "Downtrend" else if not na(htf_pivot_low_shifted) htf_trend := "Uptrend" else htf_trend := na(htf_trend[1]) ? "Sideways" : htf_trend[1]
if htf_close_shifted > htf_ma_shifted htf_trend := htf_trend == "Downtrend" ? "Sideways" : "Uptrend" else htf_trend := htf_trend == "Uptrend" ? "Sideways" : "Downtrend"
// Intermediate Time Frame Trend var string itf_trend = na if not na(itf_pivot_high_shifted) itf_trend := "Downtrend" else if not na(itf_pivot_low_shifted) itf_trend := "Uptrend" else itf_trend := na(itf_trend[1]) ? "Sideways" : itf_trend[1]
if itf_close_shifted > itf_ma_shifted itf_trend := itf_trend == "Downtrend" ? "Sideways" : "Uptrend" else itf_trend := itf_trend == "Uptrend" ? "Sideways" : "Downtrend"
// === Trend Table Display ===
- Assistant