Heikin Multi Time Frame
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MensaTrader
// Feel free to use this code but please Message/Tag me if do you re use in any fashion - Thanks and Good Luck 

//@version=5

indicator(title='Heikin MTF', overlay=false)

plots           = "=== Plots ==="
bullColor       = input.color(#00E600, title="Bull Color", group=plots)
bearColor       = input.color(#FF0000, title="Bear Color", group=plots)

timeFrames      = "=== Timeframes ==="
timeframe1      = input.timeframe("30", 'Timeframe 1', group=timeFrames)
timeframe2      = input.timeframe("60", 'Timeframe 1', group=timeFrames)
timeframe3      = input.timeframe("120", 'Timeframe 1', group=timeFrames)
timeframe4      = input.timeframe("180", 'Timeframe 1', group=timeFrames)
timeframe5      = input.timeframe("240", 'Timeframe 1', group=timeFrames)
timeframe6      = input.timeframe("D", 'Timeframe 1', group=timeFrames)
timeframe7      = input.timeframe("W", 'Timeframe 1', group=timeFrames)
timeframe8      = input.timeframe("M", 'Timeframe 1', group=timeFrames)


//*** Functions
calculateHeikinColor(timeframe) =>
    ha_t                = ticker.heikinashi(syminfo.tickerid)
    ha_open             = request.security(ha_t, str.tostring(timeframe),open)
    ha_close            = request.security(ha_t, str.tostring(timeframe),close) 


    col = ha_close > ha_open ? bullColor : bearColor

longAlert = calculateHeikinColor(timeframe1) == bullColor and calculateHeikinColor(timeframe1) == calculateHeikinColor(timeframe2) and calculateHeikinColor(timeframe2) == calculateHeikinColor(timeframe3) and calculateHeikinColor(timeframe3) == calculateHeikinColor(timeframe4) and calculateHeikinColor(timeframe4) == calculateHeikinColor(timeframe5) and calculateHeikinColor(timeframe5) == calculateHeikinColor(timeframe6) and calculateHeikinColor(timeframe6) == calculateHeikinColor(timeframe7) and calculateHeikinColor(timeframe7) == calculateHeikinColor(timeframe8)
shortAlert = calculateHeikinColor(timeframe1) == bearColor and calculateHeikinColor(timeframe1) == calculateHeikinColor(timeframe2) and calculateHeikinColor(timeframe2) == calculateHeikinColor(timeframe3) and calculateHeikinColor(timeframe3) == calculateHeikinColor(timeframe4) and calculateHeikinColor(timeframe4) == calculateHeikinColor(timeframe5) and calculateHeikinColor(timeframe5) == calculateHeikinColor(timeframe6) and calculateHeikinColor(timeframe6) == calculateHeikinColor(timeframe7) and calculateHeikinColor(timeframe7) == calculateHeikinColor(timeframe8)

alertcondition(longAlert, title="All Bullish", message="")
alertcondition(shortAlert, title="All Bearish", message="")

//Plots 
plotshape(1.00, 'Timeframe 1', shape.square, location.absolute, calculateHeikinColor(timeframe1), size=size.tiny)
plotshape(1.05, 'Timeframe 2', shape.square, location.absolute, calculateHeikinColor(timeframe2), size=size.tiny)
plotshape(1.10, 'Timeframe 3', shape.square, location.absolute, calculateHeikinColor(timeframe3), size=size.tiny)
plotshape(1.15, 'Timeframe 4', shape.square, location.absolute, calculateHeikinColor(timeframe4), size=size.tiny)
plotshape(1.20, 'Timeframe 4', shape.square, location.absolute, calculateHeikinColor(timeframe5), size=size.tiny)
plotshape(1.25, 'Timeframe 4', shape.square, location.absolute, calculateHeikinColor(timeframe6), size=size.tiny)
plotshape(1.30, 'Timeframe 4', shape.square, location.absolute, calculateHeikinColor(timeframe7), size=size.tiny)
plotshape(1.35, 'Timeframe 4', shape.square, location.absolute, calculateHeikinColor(timeframe8), size=size.tiny)

