ViVen - Multi Time Frame - Moving Average Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vijiviven

//This indicator is created by ViVen Traders for Swing Trading based on various Moving Averages
//Hi Traders,
//Indicator Description : Multiple Time Frame Moving Average lines in One Chart.
//Moving Average Types : SMA, WMA, EMA
//[b]Moving Average Period : 20 Default (Variable up to 200)
//MA Time Frame : 1m, 3m, 5m, 15m, 30m, 1Hr, Daily, Weekly, Monthly (All lines in one chart)
//You can turn ON/OFF the moving average lines based on your requirement.
//Moving Average Table : The table will give you an idea where the price is currently trading (LTP), if the price is above any of the moving average then it will show you the Price is above MA and wise versa.
//Trading Method:
//Monthly, Weekly, Daily and 1Hr Moving averages will tell you whether the script is in Bullish Trend or Bearish Trend.
//Basically the moving averages will act as Support and Resistance Levels. With candle confirmation you can take trade.
//Ready to Take Position - When 1m MA Crosses 3m MA (Upside / Downside)
//BUY Strategy:
//"Buy"              - when 3m MA breaks 5m moving average on the upside. (Intraday/Scalp)
//"Hold"             - when 5m MA breaks 15m MA on the upside.
//"Strong Hold"  - when 15m MA breaks 1Hr MA on the upside for Long term.
//"Exit"              - when 3m MA breaks 5m MA on the Downside.
//SELL Strategy:
//"Sell"              - when 3m MA breaks 5m moving average on the Downside. (Intraday/Scalp)
//"Hold"             - when 5m MA breaks 15m MA on the Downside. (Intraday)
//"Strong Hold"  - when 15m MA breaks 1Hr MA on the Downside. (Positional).
//"Exit"              - when 3m MA breaks 5m MA on the Downside.
//If you agree with this strategy and works well please like this script, share it with your friends and Follow me for more Indicators.

//@version=5
indicator(title='ViVen - MTF MA', shorttitle='ViVen - MTF MA ⚡', overlay=true)


Vi = input.bool(true, title='On/Off All Indicators', group='⚡  DISPLAY INDICATORS ⚡ ')
Vt = input.bool(true, title='Display MA Table', group='⚡  MOVING AVG ⚡ ')
MA1_3m = input.bool(false, title='👉 Display 1m-3m MA', group='⚡  MOVING AVG ⚡ ')
MA5m = input.bool(true, title='👉 Display 5m MA', group='⚡  MOVING AVG ⚡ ')
MA15m = input.bool(true, title='👉 Display 15m MA', group='⚡  MOVING AVG ⚡ ')
MA30m = input.bool(false, title='👉 Display 30m MA', group='⚡  MOVING AVG ⚡ ')
MA1h = input.bool(true, title='👉 Display 60m MA', group='⚡  MOVING AVG ⚡ ')
MA1d = input.bool(true, title='👉 Display 1 Day MA', group='⚡  MOVING AVG ⚡ ')
MA1w = input.bool(true, title='👉 Display 1 Week MA', group='⚡  MOVING AVG ⚡ ')
MA1m = input.bool(true, title='👉 Display 1 Month MA', group='⚡  MOVING AVG ⚡ ')

MAtype = input.string(title='MA Type', defval='SMA', options=['SMA', 'EMA', 'WMA'], group='INDICATOR INPUT 🔨')
MAv = input.int(title='Moving Avg Period', minval=1, maxval=300, defval=200, group='INDICATOR INPUT 🔨')


dash_loc = input.string("Top Right","Dashboard Location"  ,options=["Top Right","Bottom Right","Top Left","Middle Left", "Bottom Left", "Middle Right","Bottom Center"]  ,group='Dashboard Style Settings 📜')
text_size = input.string('Normal',"Dashboard Size"  ,options=["Tiny","Small","Normal","Large"]  ,group='Dashboard Style Settings 📜')
txt_col = input.color(color.black, 'Text/Frame Color', group='Dashboard Style Settings 📜')
cell_transp = input.int(50, 'Cell Transparency', minval=0, maxval=100, group='Dashboard Style Settings 📜')
var table_position = dash_loc == 'Top Left' ? position.top_left : dash_loc == 'Bottom Left' ? position.bottom_left : dash_loc == 'Middle Left' ? position.middle_left : dash_loc == 'Middle Right' ? position.middle_right : dash_loc == 'Bottom Center' ? position.bottom_center : dash_loc == 'Top Right' ? position.top_right : position.bottom_right
var table_text_size = text_size == 'Tiny' ? size.tiny : text_size == 'Small' ? size.small : text_size == 'Normal' ? size.normal : size.large
var t = table.new(table_position, 2, 15, frame_color=txt_col, frame_width=1, border_color=txt_col, border_width=1)
BorderThickness = 1
TableWidth = 0
FirstRowFirstColumnColor = color.new(color.orange, 0)


ma_function(close, MAv) =>
    if MAtype == 'SMA'
        ta.sma(close, MAv)
    else
        if MAtype == 'EMA'
            ta.ema(close, MAv)
        else
            if MAtype == 'WMA'
                ta.wma(close, MAv)
            else
                ta.sma(close, MAv)


MAvlen = ma_function(close, MAv)


//Different Time Frame Values
plot1mma = request.security(syminfo.tickerid, '1', MAvlen)
plot3mma = request.security(syminfo.tickerid, '3', MAvlen)
plot5mma = request.security(syminfo.tickerid, '5', MAvlen)
plot15mma = request.security(syminfo.tickerid, '15', MAvlen)
plot30mma = request.security(syminfo.tickerid, '30', MAvlen)
plot1hma = request.security(syminfo.tickerid, '60', MAvlen)
plot1dma = request.security(syminfo.tickerid, 'D', MAvlen)
plot1wma = request.security(syminfo.tickerid, 'W', MAvlen)
plot1mmma = request.security(syminfo.tickerid, 'M', MAvlen)


// Plot the SMAs
plot(Vi and MA1_3m ? plot1mma : na, title='MA 1m', linewidth=1, color=color.gray, transp=1)
plot(Vi and MA1_3m ? plot3mma : na, title='MA 3m', linewidth=1, color=color.orange, transp=1)
plot(Vi and MA5m ? plot5mma : na, title='MA 5m', linewidth=2, color=color.blue, transp=1)
plot(Vi and MA15m ? plot15mma : na, title='MA 15m', linewidth=3, color=color.fuchsia, transp=1)
plot(Vi and MA30m ? plot30mma : na, title='MA 30m', linewidth=1, color=color.teal, transp=1)
plot(Vi and MA1h ? plot1hma : na, title='MA 1h', linewidth=3, color=color.maroon, transp=1)
plot(Vi and MA1d ? plot1dma : na, title='MA D', linewidth=4, color=color.purple, transp=1)
plot(Vi and MA1w ? plot1wma : na, title='MA W', linewidth=5, color=color.black, transp=1)
plot(Vi and MA1m ? plot1mmma : na, title='MA M', linewidth=6, color=color.red, transp=1)

// Moving Average Vs Price Strategy
pr_1mma = plot1mma < close ? 'Price Above 1m MA' : 'Price Below 1m MA'
pr_1mmacolor = plot1mma < close ? #00E81F : #E80800
pr_3mma = plot3mma < close ? 'Price Above 3m MA' : 'Price Below 3m MA'
pr_3mmacolor = plot3mma < close ? #00E81F : #E80800
pr_5mma = plot5mma < close ? 'Price Above 5m MA' : 'Price Below 5m MA'
pr_5mmacolor = plot5mma < close ? #00E81F : #E80800
pr_15mma = plot15mma < close ? 'Price Above 15m MA' : 'Price Below 15m MA'
pr_15mmacolor = plot15mma < close ? #00E81F : #E80800
pr_30mma = plot30mma < close ? 'Price Above 30m MA' : 'Price Below 30m MA'
pr_30mmacolor = plot30mma < close ? #00E81F : #E80800
pr_1hma = plot1hma < close ? 'Price Above 1Hr MA' : 'Price Below 1Hr MA'
pr_1hmacolor = plot1hma < close ? #00E81F : #E80800
pr_1dma = plot1dma < close ? 'Price Above Daily MA' : 'Price Below Daily MA'
pr_1dmacolor = plot1dma < close ? #00E81F : #E80800
pr_1wma = plot1wma < close ? 'Price Above Weekly MA' : 'Price Below Weekly MA'
pr_1wmacolor = plot1wma < close ? #00E81F : #E80800
pr_1mmma = plot1mmma < close ? 'Price Above Monthly MA' : 'Price Below Monthly MA'
pr_1mmmacolor = plot1mmma < close ? #00E81F : #E80800

if barstate.islast and Vi and Vt

    table.cell(t, 0, 0, MAtype + ' - ' + str.tostring(MAv), bgcolor=#C4C7C3, text_size=table_text_size, text_color=#000000, width=TableWidth)
    table.cell(t, 1, 0, 'Price At', bgcolor=#C4C7C3, text_size=table_text_size, text_color=#000000, width=TableWidth)

    table.cell(t, 0, 1, '1m ' + MAtype, bgcolor=FirstRowFirstColumnColor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    table.cell(t, 1, 1, pr_1mma, bgcolor=pr_1mmacolor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    
    table.cell(t, 0, 2, '3m ' + MAtype, bgcolor=FirstRowFirstColumnColor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    table.cell(t, 1, 2, pr_3mma, bgcolor=pr_3mmacolor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    
    table.cell(t, 0, 3, '5m ' + MAtype, bgcolor=FirstRowFirstColumnColor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    table.cell(t, 1, 3, pr_5mma, bgcolor=pr_5mmacolor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    
    table.cell(t, 0, 4, '15m ' + MAtype, bgcolor=FirstRowFirstColumnColor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    table.cell(t, 1, 4, pr_15mma, bgcolor=pr_15mmacolor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    
    table.cell(t, 0, 5, '30m ' + MAtype, bgcolor=FirstRowFirstColumnColor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    table.cell(t, 1, 5, pr_30mma, bgcolor=pr_30mmacolor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    
    table.cell(t, 0, 6, '1Hr ' + MAtype, bgcolor=FirstRowFirstColumnColor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    table.cell(t, 1, 6, pr_1hma, bgcolor=pr_1hmacolor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    
    table.cell(t, 0, 7, 'Daily ' + MAtype, bgcolor=FirstRowFirstColumnColor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    table.cell(t, 1, 7, pr_1dma, bgcolor=pr_1dmacolor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    
    table.cell(t, 0, 8, 'Weekly ' + MAtype, bgcolor=FirstRowFirstColumnColor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    table.cell(t, 1, 8, pr_1wma, bgcolor=pr_1wmacolor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    
    table.cell(t, 0, 9, 'Monthly ' + MAtype, bgcolor=FirstRowFirstColumnColor, text_size=table_text_size, text_color=#000000, width=TableWidth)
    table.cell(t, 1, 9, pr_1mmma, bgcolor=pr_1mmmacolor, text_size=table_text_size, text_color=#000000, width=TableWidth)


