Multi-Timeframe High Low (@JP7FX)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jp7fx

//@version=5

indicator('Multi-Timeframe High Low (@JP7FX)', overlay=true)

S1 = '----Inputs----'
S2 = '----Line and Label Settings----'

/////Inputs - Shown in Menu 
TF = input.timeframe(title='High/Low Timeframe', defval='D', group=S1)
showHigh = input.bool(title='Show High Levels', defval=true, group=S1)
showLow = input.bool(title='Show Low Levels', defval=true, group=S1)
showLabel = input.bool(title='Show Levels Label', defval=true, group=S1)


lineWidth = input.int(title='Line Width', defval=1, minval=1, group=S2)
highColor = input.color(title='High Level Color', defval=color.red, group=S2)
lowColor = input.color(title='Low Level Color', defval=color.green, group=S2)
labelTextColor = input.color(title='Label Text Color', defval=color.rgb(0, 0, 0), group=S2)

////Request High / Low Data 
Prev_high = request.security(syminfo.tickerid, TF, high[1], barmerge.gaps_off, lookahead=barmerge.lookahead_on)
Prev_low = request.security(syminfo.tickerid, TF, low[1], barmerge.gaps_off, lookahead=barmerge.lookahead_on)

///// Plot the breakout levels
plot(showHigh ? Prev_high: na, color=color.new(highColor, 0), style=plot.style_stepline, linewidth=lineWidth)

plot(showLow ? Prev_low: na, color=color.new(lowColor, 0), style=plot.style_stepline, linewidth=lineWidth)

var label highLabel = na
var label lowLabel = na

// Add labels for high and low levels
if showHigh and showLabel and barstate.islast
    label.delete(highLabel) // Remove previous high label
    highLabel := label.new(x=bar_index, y=Prev_high, text="High (" + str.tostring(TF) + ")", textcolor=labelTextColor, color=highColor, style=label.style_label_left, yloc=yloc.price)

if showLow and showLabel and barstate.islast
    label.delete(lowLabel) // Remove previous low label
    lowLabel := label.new(x=bar_index, y=Prev_low, text="Low (" + str.tostring(TF) + ")", textcolor=labelTextColor, color=lowColor, style=label.style_label_left, yloc=yloc.price)

// Alert conditions
highTaken = ta.crossover(high, Prev_high)
lowTaken = ta.crossunder(low, Prev_low)

alertcondition(highTaken, title='High Level Alert', message='Price has taken the high level')
alertcondition(lowTaken, title='Low Level Alert', message='Price has taken the low level')
alertcondition(highTaken or lowTaken, title='Level Alert', message='Price has taken a level')

//// End Of Script

