6 Multi-Timeframe Supertrend with Heikin Ashi as Source
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @Shamshiri_investments
// Author : Mohammad Hossein Shamshiri
//
//@version=5
indicator(title="6 Multi-Timeframe supertrend with Heikin Ashi source",shorttitle="6 Heikin Ashi supertrend", overlay = true,timeframe="")

Mult = input.float(defval = 1.0, title = "ATR Factor", minval = 0.5, maxval = 100, step = 0.1)
Mult2 = input.float(defval = 2.0, title = "ATR Factor", minval = 0.5, maxval = 100, step = 0.1)
Mult3 = input.float(defval = 3.0, title = "ATR Factor", minval = 0.5, maxval = 100, step = 0.1)
Mult4 = input.float(defval = 4.0, title = "ATR Factor", minval = 0.5, maxval = 100, step = 0.1)
Mult5 = input.float(defval = 5.0, title = "ATR Factor", minval = 0.5, maxval = 100, step = 0.1)
Mult51 = input.float(defval = 6.0, title = "ATR Factor", minval = 0.5, maxval = 100, step = 0.1)

Period = input.int(defval = 7, title = "ATR Period", minval = 1,maxval = 100)

//Heikin Ashi high, low, close
h = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)
l = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)
c = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)

//HeikinAshi atr
Atr = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, ta.atr(Period))

Up = (h + l) / 2 - (Mult * Atr)
Dn = (h + l) / 2 + (Mult * Atr)

float TUp = na
float TDown = na
Trend = 0

TUp := c[1] > TUp[1] ? math.max(Up,TUp[1]) : Up
TDown := c[1] < TDown[1] ? math.min(Dn,TDown[1]) : Dn
Trend := c > TDown[1] ? 1: c < TUp[1]? -1: nz(Trend[1],1)
Trailingsl = Trend == 1 ? TUp : TDown

plot(Trailingsl, color = color.blue ,  linewidth = 2, title = "SuperTrend 1")


Up2 = (h + l) / 2 - (Mult2 * Atr)
Dn2 = (h + l) / 2 + (Mult2 * Atr)

float TUp2 = na
float TDown2 = na
Trend2 = 0

TUp2 := c[1] > TUp2[1] ? math.max(Up2,TUp2[1]) : Up2
TDown2 := c[1] < TDown2[1] ? math.min(Dn2,TDown2[1]) : Dn2
Trend2 := c > TDown2[1] ? 1: c < TUp2[1]? -1: nz(Trend2[1],1)
Trailingsl2 = Trend2 == 1 ? TUp2 : TDown2

plot(Trailingsl2, color = color.orange ,  linewidth = 2, title = "SuperTrend 2")

Up3 = (h + l) / 2 - (Mult3 * Atr)
Dn3 = (h + l) / 2 + (Mult3 * Atr)

float TUp3 = na
float TDown3 = na
Trend3 = 0

TUp3 := c[1] > TUp3[1] ? math.max(Up3,TUp3[1]) : Up3
TDown3 := c[1] < TDown3[1] ? math.min(Dn3,TDown3[1]) : Dn3
Trend3 := c > TDown3[1] ? 1: c < TUp3[1]? -1: nz(Trend3[1],1)
Trailingsl3 = Trend3 == 1 ? TUp3 : TDown3

plot(Trailingsl3, color = color.black ,  linewidth = 2, title = "SuperTrend 3")

Up4 = (h + l) / 2 - (Mult4 * Atr)
Dn4 = (h + l) / 2 + (Mult4 * Atr)

float TUp4 = na
float TDown4 = na
Trend4 = 0

TUp4 := c[1] > TUp4[1] ? math.max(Up4,TUp4[1]) : Up4
TDown4 := c[1] < TDown4[1] ? math.min(Dn4,TDown4[1]) : Dn4
Trend4 := c > TDown4[1] ? 1: c < TUp4[1]? -1: nz(Trend4[1],1)
Trailingsl4 = Trend4 == 1 ? TUp4 : TDown4

plot(Trailingsl4, color = color.lime ,  linewidth = 2, title = "SuperTrend 4")

Up5 = (h + l) / 2 - (Mult5 * Atr)
Dn5 = (h + l) / 2 + (Mult5 * Atr)

float TUp5 = na
float TDown5 = na
Trend5 = 0

TUp5 := c[1] > TUp5[1] ? math.max(Up5,TUp5[1]) : Up5
TDown5 := c[1] < TDown5[1] ? math.min(Dn5,TDown5[1]) : Dn5
Trend5 := c > TDown5[1] ? 1: c < TUp5[1]? -1: nz(Trend5[1],1)
Trailingsl5 = Trend5 == 1 ? TUp5 : TDown5

plot(Trailingsl5, color = color.teal ,  linewidth = 2, title = "SuperTrend 5")

Up51 = (h + l) / 2 - (Mult51 * Atr)
Dn51 = (h + l) / 2 + (Mult51 * Atr)

float TUp51 = na
float TDown51 = na
Trend51 = 0

TUp51 := c[1] > TUp51[1] ? math.max(Up51,TUp51[1]) : Up5
TDown51 := c[1] < TDown51[1] ? math.min(Dn51,TDown51[1]) : Dn5
Trend51 := c > TDown51[1] ? 1: c < TUp51[1]? -1: nz(Trend51[1],1)
Trailingsl51 = Trend51 == 1 ? TUp51 : TDown51

plot(Trailingsl51, color = color.maroon ,  linewidth = 2, title = "SuperTrend 6")

//Alerts
alertcondition(Trend3 == 1 and Trend3[1] == -1, title='Supertrend 3 Trend Up', message='Supertrend 3 Trend Up')
alertcondition(Trend3 == -1 and Trend3[1] == 1, title='Supertrend 3 Trend Down', message='Supertrend 3 Trend Down')

