Certainly! I've modified your Pine Script code to allow users to disable multiple time frames and focus on a single time frame trend. Users can now choose whether to display the Higher Time Frame (HTF) trend, the Intermediate Time Frame (ITF) trend, or both, through new input options. Here's the updated script:
//@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")
// Time Frame Enable Inputs
htf_enabled = input.bool(true, "Show Higher Time Frame Trend")
itf_enabled = input.bool(true, "Show Intermediate Time Frame Trend")
// Pivot Parameters
pivot_left = input.int(5, "Pivot Left Bars", minval=1)
pivot_right = input.int(5, "Pivot Right Bars", minval=1)
// Moving Average Length
ma_length = input.int(21, "MA Length")
// === Time Frame Data Retrieval ===
// Higher Time Frame Data
var float htf_high = na
var float htf_low = na
var float htf_close = na
if htf_enabled
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
var float itf_high = na
var float itf_low = na
var float itf_close = na
if itf_enabled
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
var float htf_pivot_high = na
var float htf_pivot_low = na
var float htf_pivot_high_shifted = na
var float htf_pivot_low_shifted = na
var float htf_close_shifted = na
if htf_enabled
htf_pivot_high := ta.pivothigh(htf_high, pivot_left, pivot_right)
htf_pivot_low := ta.pivotlow(htf_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]
// Intermediate Time Frame Pivots
var float itf_pivot_high = na
var float itf_pivot_low = na
var float itf_pivot_high_shifted = na
var float itf_pivot_low_shifted = na
var float itf_close_shifted = na
if itf_enabled
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
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 ===
// Higher Time Frame Moving Average
var float htf_ma = na
var float htf_ma_shifted = na
if htf_enabled
htf_ma := ta.sma(htf_close, ma_length)
htf_ma_shifted := htf_ma[pivot_right]
// Intermediate Time Frame Moving Average
var float itf_ma = na
var float itf_ma_shifted = na
if itf_enabled
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 htf_enabled
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 itf_enabled
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 ===
// Create Table with 1 column and 2 rows (max)
var table trend_table = table.new(position.top_right, 1, 2, border_width=1)
// Default Trend Table Colors
htf_trend_up_color_default = color.new(color.green, 70)
htf_trend_down_color_default = color.new(color.red, 70)
htf_trend_sideways_color_default = color.new(color.orange, 70)
itf_trend_up_color_default = color.new(color.green, 70)
itf_trend_down_color_default = color.new(color.red, 70)
itf_trend_sideways_color_default = color.new(color.orange, 70)
// Update the table cells
int currentRow = 0
if htf_enabled
// Apply colors to the trend backgrounds
htf_bgcolor = htf_trend == "Uptrend" ? htf_trend_up_color_default :
htf_trend == "Downtrend" ? htf_trend_down_color_default :
htf_trend_sideways_color_default
// Update the table cell
table.cell(trend_table, 0, currentRow, "HTF Trend: " + htf_trend, text_color=color.white, bgcolor=htf_bgcolor)
currentRow += 1
if itf_enabled
// Apply colors to the trend backgrounds
itf_bgcolor = itf_trend == "Uptrend" ? itf_trend_up_color_default :
itf_trend == "Downtrend" ? itf_trend_down_color_default :
itf_trend_sideways_color_default
// Update the table cell
table.cell(trend_table, 0, currentRow, "ITF Trend: " + itf_trend, text_color=color.white, bgcolor=itf_bgcolor)
currentRow += 1
// === Pivot Plotting Management ===
// Default pivot plot styles
htf_pivot_high_color_default = color.red
htf_pivot_low_color_default = color.lime
itf_pivot_high_color_default = color.purple
itf_pivot_low_color_default = color.yellow
pivot_shape_size = size.tiny
// Plot pivot points for HTF
htf_pivot_high_plot = htf_enabled and not na(htf_pivot_high_shifted) ? htf_high[pivot_right * 2] : na
plotshape(htf_pivot_high_plot, title="HTF Pivot High", style=shape.triangledown, location=location.absolute, color=htf_pivot_high_color_default, size=pivot_shape_size, offset=-pivot_right * 2)
htf_pivot_low_plot = htf_enabled and not na(htf_pivot_low_shifted) ? htf_low[pivot_right * 2] : na
plotshape(htf_pivot_low_plot, title="HTF Pivot Low", style=shape.triangleup, location=location.absolute, color=htf_pivot_low_color_default, size=pivot_shape_size, offset=-pivot_right * 2)
// Plot pivot points for ITF
itf_pivot_high_plot = itf_enabled and not na(itf_pivot_high_shifted) ? itf_high[pivot_right * 2] : na
plotshape(itf_pivot_high_plot, title="ITF Pivot High", style=shape.triangledown, location=location.absolute, color=itf_pivot_high_color_default, size=pivot_shape_size, offset=-pivot_right * 2)
itf_pivot_low_plot = itf_enabled and not na(itf_pivot_low_shifted) ? itf_low[pivot_right * 2] : na
plotshape(itf_pivot_low_plot, title="ITF Pivot Low", style=shape.triangleup, location=location.absolute, color=itf_pivot_low_color_default, size=pivot_shape_size, offset=-pivot_right * 2)
// === Moving Averages Plotting ===
// Plot the moving averages (properties adjustable from the Style tab)
htf_ma_plot = htf_enabled ? htf_ma : na
plot(htf_ma_plot, title="HTF MA")
itf_ma_plot = itf_enabled ? itf_ma : na
plot(itf_ma_plot, title="ITF MA")
Explanation of Changes:
Now, when you add this indicator to your chart, you can choose to display only one time frame's trend by setting Show Higher Time Frame Trend or Show Intermediate Time Frame Trend to false in the inputs. This flexibility allows you to focus on a single time frame's trend without the clutter of additional information.
Feel free to adjust the time frames, pivot parameters, and moving average length as needed. Let me know if you have any questions or need further assistance!