Donchian Channels Multitimeframe Jaime
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jaimecruz3
// Create the popular Donchian Chanels in Multiframe periods

//@version=5
indicator('Donchian Channels Multitimeframe Jaime', overlay=true)

// GET TIMEFRAMES

TimeframeU = input.string(defval='Auto', title='Higher Time Frame', options=['Auto', '1', '3', '5', '10', '15', '30', '60', '120', '180', '240', '360', '480', '720', 'D', 'W', '2W', 'M', '3M', '6M', '12M'])
higher_tf = TimeframeU == 'Auto' ? timeframe.period == '1' ? '60' : timeframe.period == '2' ? '60' : timeframe.period == '3' ? '60' : timeframe.period == '5' ? '60' : timeframe.period == '10' ? '120' : timeframe.period == '15' ? '120' : timeframe.period == '30' ? 'D' : timeframe.period == '45' ? 'D' : timeframe.period == '60' ? 'D' : timeframe.period == '120' ? 'D' : timeframe.period == '180' ? 'D' : timeframe.period == '240' ? 'D' : timeframe.period == 'D' ? 'W' : timeframe.period == 'W' ? 'M' : timeframe.period : TimeframeU
actual_tf = timeframe.period
donchian_period = input.int(defval=20, minval=1, title="Donchian Periods", group="General options")

var bool_bullish_donchian_trend = false

donchian(highSource, lowSource, rangeLength)=>
    top = ta.highest(highSource, rangeLength)
    bottom = ta.lowest(lowSource, rangeLength)
    middle = (top+bottom)/2
    [middle, top, bottom]

[donchian_middle, donchian_upper, donchian_lower] = request.security(syminfo.tickerid, actual_tf, donchian(high, low, donchian_period), lookahead=barmerge.lookahead_off)

[donchian_middle_HTF, donchian_upper_HTF, donchian_lower_HTF] = request.security(syminfo.tickerid, higher_tf, donchian(high, low, donchian_period), lookahead=barmerge.lookahead_off)
plot(donchian_upper, color=color.new(color.gray, 0), editable=false)
mdonchian = plot(donchian_middle, color=color.new(color.yellow, 0), editable=false)
plot(donchian_lower, color=color.new(color.gray, 0), editable=false)

plot(donchian_upper_HTF, color=color.new(color.blue, 0), editable=false)
mdonchian_HTF = plot(donchian_middle_HTF, color=color.new(color.orange, 0), editable=false)
plot(donchian_lower_HTF, color=color.new(color.blue, 0), editable=false)

// See trend
if close >= donchian_upper[1]
    bool_bullish_donchian_trend := true 
if close <= donchian_lower[1]
    bool_bullish_donchian_trend := false

// plotshape(bool_bullish_donchian_trend, style=shape.triangleup, location=location.abovebar, color=color.green)
// plotshape(not bool_bullish_donchian_trend, style=shape.triangledown, location=location.belowbar, color=color.red)
fill(mdonchian, mdonchian_HTF, color=color.yellow, title='Middle donchian')



