MACDV DASHBOARD
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © KP_House

//@version=5
indicator("MACDV DASHBOARD", overlay=true)
//Start dashboard
// ---- Table Settings Start ----//
max    = 160    //Maximum Length
min    = 10     //Minimum Length


// Input setting page start
dash_loc    = input.session("Top Right","Dashboard Location"  ,options=["Top Right","Bottom Right","Top Left","Bottom Left", "Middle Right","Bottom Center"]  ,group='Style Settings')
text_size   = input.session('Small',"Dashboard Size"  ,options=["Tiny","Small","Normal","Large"]  ,group='Style Settings')
cell_up     = input.color(color.green,'Up Cell Color'  ,group='Style Settings')
cell_dn     = input.color(color.red,'Down Cell Color'  ,group='Style Settings')
cell_Neut   = input.color(color.gray,'Nochange  Cell Color'  ,group='Style Settings')
row_col     = color.blue
col_col     = color.white
txt_col     = color.white
cell_transp = input.int(60,'Cell Transparency'  ,minval=0  ,maxval=100  ,group='Style Settings')

Header_col  = color.new(#a49627,50)
//MACDV color
cell_MACDV1 = input.color(color.teal,'Buy Risk'  ,inline='indicator1',group='Style Settings')
cell_MACDV2 = input.color(color.green,'Rallying' ,inline='indicator1', group='Style Settings')
cell_MACDV3 = input.color(color.red,'Retracing'  ,inline='indicator2', group='Style Settings')
cell_MACDV4 = input.color(color.yellow,'Ranging'  ,inline='indicator2', group='Style Settings')
cell_MACDV5 = input.color(color.green,'Rebounding',inline='indicator3', group='Style Settings')
cell_MACDV6 = input.color(color.red,'Reverting'  ,inline='indicator3', group='Style Settings')
cell_MACDV7 = input.color(color.maroon,'Sell Risk',inline='indicator4', group='Style Settings')
//Momentum color
cell_phase1 = input.color(color.green,'Phase1:Accumulation'  ,inline='indicator6', group='Style Settings')
cell_phase2 = input.color(color.teal,'Phase2:Bullish'  ,inline='indicator6', group='Style Settings')
cell_phase3 = input.color(color.red,'Phase3:Warning'  ,inline='indicator7', group='Style Settings')
cell_phase4 = input.color(color.red,'Phase4:Distribution'  ,inline='indicator7', group='Style Settings')
cell_phase5 = input.color(color.orange,'Phase5:Bearish'  ,inline='indicator8', group='Style Settings')
cell_phase6 = input.color(color.green,'Phase6:Recovery'  ,inline='indicator8', group='Style Settings')
// ---- Table Settings End ----}//

// ---- Indicators Show/Hide Settings Start ----//

showCls     = input.bool(defval=true, title="Show Price Close", inline='indicator1', group="Columns Settings")
showMA01    = input.bool(defval=true, title="Show MA01", inline='indicator1', group="Columns Settings")
showMA02    = input.bool(defval=true, title="Show MA02", inline='indicator1', group="Columns Settings")
showRSI     = input.bool(defval=true, title="Show RSI :", inline='indicator2', group="Columns Settings")
showADX     = input.bool(defval=true, title="Show ADX", inline='indicator2', group="Columns Settings")
showMACDV   = input.bool(defval=true, title="Show MACDV", inline='indicator2', group="Columns Settings")
showSignalV = input.bool(defval=true, title="Show SignalV", inline='indicator3', group="Columns Settings")
showMACDV_Status = input.bool(defval=true, title="Show MACDV_Status", inline='indicator3', group="Columns Settings")
showmomentum = input.bool(defval=true, title="Show Momentum", inline='indicator3', group="Columns Settings")
// ---- Indicators Show/Hide Settings end ----}//


// ---- Timeframe Row Show/Hide Settings Start ----//
showTF1 = input.bool(defval=true, title="Show TF MN", inline='indicator1',group="Rows Settings")


//---- Indicators code Start ----//
CLS= close[1]

//---- RSI code start ----//
rsiPeriod   = 14
RSI         = ta.rsi(close, rsiPeriod)

//---- RSI code end ----//

//---- EMA 1 code start----//
length_MA1 = input.int(title="MA1",defval=50, minval=1)
MA1        = ta.ema(close, length_MA1)
//plot(MA01, color=color.red, title="MA1")
//---- EMA 1  code end ----//

//---- EMA 2 code start---//
length_MA2 = input.int(title="MA2",defval=200, minval=1)
MA2        = ta.ema(close, length_MA2)
//plot(MA02, color=color.blue, title="MA2")
//---- EMA 2  code end ----//

//---- MACD-V code start ----//
MACD_fast_length    = input(title="MACD Fast", defval=12)
MACD_slow_length    = input(title="MACD Slow", defval=26)
MACD_signal_length  = input.int(title="MACD Signal ",  minval = 1, maxval = 50, defval = 9)
MACD_atr_length     = input(title="ATR ", defval=26)

// Input seeting page end
// Calculating 
fast_ma =  ta.ema(close, MACD_fast_length)
slow_ma =  ta.ema(close, MACD_slow_length)
atr     =  ta.atr(MACD_atr_length)
MACDV   = (((fast_ma - slow_ma)/atr)*100)//[( 12 bar EMA - 26 bar EMA) / ATR(26) ] * 100
SignalV = ta.ema(MACDV, MACD_signal_length)
//---- MACD-V code end ----//

//---- Indicators code end ----//


//-----Condition start
stringmacdv     =(MACDV>150) ? "Buy Risk" :(MACDV>50 and MACDV<150 and MACDV>SignalV ) ? "Rallying" :(MACDV>50 and MACDV<150 and MACDV<SignalV ) ? "Retracing":(MACDV<50) and (MACDV>-50) ? "Ranging" :(MACDV<-50 and MACDV>-150 and MACDV>SignalV ) ? "Rebounding":(MACDV<-50 and MACDV>-150 and MACDV<SignalV ) ? "Reversing":(MACDV<150) ? "Sell Risk" :na
//momentum
stringmomentum  =(CLS>MA1 and CLS>MA2 and MA1<MA2) ? "Phase I Accumulation: Buy#2" :(CLS>MA1 and CLS>MA2 and MA1>MA2) ? "Phase II Bullish: Buy#Exit":(CLS<MA1 and CLS>MA2 and MA1>MA2) ? "Phase III Warning: Sell#1":(CLS<MA1 and CLS<MA2 and MA1>MA2) ? "Phase IV Distribution: Sell#2":(CLS<MA1 and CLS<MA2 and MA1<MA2) ? "Phase V Bearish: Sell#Exit":(CLS>MA1 and CLS<MA2 and MA1<MA2) ? "Phase IV Recovery: Entry#1":na
    
//-----Condition end

//-------------- Table code Start -------------------//

//---- Table Position & Size code start {----//
var table_position = dash_loc == 'Top Left' ? position.top_left :
  dash_loc == 'Bottom Left' ? position.bottom_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,15,math.abs(max-min)+2,
  frame_color   =color.new(#000000,0),
  frame_width   =1,
  border_color  =color.new(#000000,0),
  border_width  =1)
//---- Table Position & Size code end ----//

//---- Table Column & Rows code start ----//
if (barstate.islast)
//---- Table Main Column Headers code start ----//

    if showCls
        table.cell(t,1,1,'Close-1',text_color=col_col,text_size=table_text_size,bgcolor=Header_col)
    if showMA01
        table.cell(t,2,1,'MA01',text_color=col_col,text_size=table_text_size,bgcolor=Header_col)
    if showMA02
        table.cell(t,3,1,'MA02',text_color=col_col,text_size=table_text_size,bgcolor=Header_col)

    if showRSI
        table.cell(t,4,1,'RSI 14',text_color=col_col,text_size=table_text_size,bgcolor=Header_col)
    if showMACDV
        table.cell(t,5,1,'MACDV',text_color=col_col,text_size=table_text_size,bgcolor=Header_col)
    if SignalV
        table.cell(t,6,1,'SignalV',text_color=col_col,text_size=table_text_size,bgcolor=Header_col)
    if showMACDV_Status
        table.cell(t,7,1,'MACDV_Status',text_color=col_col,text_size=table_text_size,bgcolor=Header_col)
    if showmomentum
        table.cell(t,8,1,'Momentum',text_color=col_col,text_size=table_text_size,bgcolor=Header_col)   
    
//---- Table Main Column Headers code end ----//

//---- Display data code start ----//
    //Month data strt
    //atrD=request.security(syminfo.tickerid,"D",a)
//    if  showTF1
//        table.cell(t,0,2, "M",text_color=col_col,text_size=table_text_size,bgcolor=Header_col)
    if  showCls
        table.cell(t,1,2, str.tostring(CLS, '#.###'),text_color=color.new(CLS >CLS[2] ? cell_up : cell_dn ,0),text_size=table_text_size, bgcolor=color.new(CLS >CLS[2] ? cell_up : cell_dn ,cell_transp))
    if  showMA01
        table.cell(t,2,2, str.tostring(MA1, '#.###'),text_color=color.new(MA1 >MA1[1] ? cell_up : cell_dn ,0),text_size=table_text_size, bgcolor=color.new(MA1 >MA1[1]  ? cell_up : cell_dn ,cell_transp))
    if  showMA02
        table.cell(t,3,2, str.tostring(MA2, '#.###'),text_color=color.new(MA2 >MA2[1] ? cell_up : cell_dn ,0),text_size=table_text_size, bgcolor=color.new(MA2 >MA2[1] ? cell_up : cell_dn ,cell_transp))
    if  showRSI
        table.cell(t,4,2, str.tostring(RSI, '#.###'),text_color=color.new(RSI > 50 ? cell_up : cell_dn ,0),text_size=table_text_size, bgcolor=color.new(RSI > 50 ? cell_up : cell_dn ,cell_transp))
    if  showMACDV
        table.cell(t,5,2,str.tostring(MACDV, '#.###'),text_color=color.new(MACDV > MACDV[1] ? cell_up : cell_dn ,0),text_size=table_text_size, bgcolor=color.new(MACDV > MACDV[1] ? cell_up : cell_dn ,cell_transp))
    if  showSignalV
        table.cell(t,6,2,str.tostring(SignalV, '#.###'),text_color=color.new(SignalV > SignalV[1] ? cell_up : cell_dn ,0),text_size=table_text_size, bgcolor=color.new(SignalV> SignalV[1] ? cell_up : cell_dn ,cell_transp))
    if  showMACDV_Status
        table.cell(t,7,2,stringmacdv,text_color=color.white,text_size=table_text_size, bgcolor=color.new(MACDV>50 ? cell_up :MACDV<-50 ?  cell_dn:cell_MACDV4  ,cell_transp)) 
    if  showmomentum
        table.cell(t,8,2,stringmomentum,text_color=color.white,text_size=table_text_size, bgcolor=color.new(CLS>MA1 and CLS>MA2 and MA1<MA2 ? cell_phase1 : (CLS>MA1 and CLS>MA2 and MA1>MA2) ? cell_phase2 : (CLS<MA1 and CLS>MA2 and MA1>MA2) ?cell_phase3 :(CLS<MA1 and CLS<MA2 and MA1>MA2) ? cell_phase4:(CLS<MA1 and CLS<MA2 and MA1<MA2) ? cell_phase5:(CLS>MA1 and CLS<MA2 and MA1<MA2) ? cell_phase6:col_col,cell_transp))

       
       
       
       
//---- Display data code end ----//
//End dahs board



