Ultra Magic 2.0 [Jay Jani]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jayjani0007

//@version=4
study(title="Warrior Thunderbolt Indicator 2.0", shorttitle="WTI 2.0", overlay=true) 
showpivot       = input(defval = false, title="Show CPR")
showVWAP        = input(title="Show VWAP", type=input.bool, defval=false)
showVWMA        = input(title="Show VWMA", type=input.bool, defval=false)
showPSAR        = input(title="Show PSAR", type=input.bool, defval=false)
showBB          = input(title="Show BB", type=input.bool, defval=false)
showEMA9        = input(title="Show EMA-9", type=input.bool, defval=false)
showEMA20       = input(title="Show EMA-20", type=input.bool, defval=false)
showEMA50       = input(title="Show EMA-50", type=input.bool, defval=false)
showEMA100      = input(title="Show EMA-100", type=input.bool, defval=false)
showSMA9        = input(title="Show SMA-9", type=input.bool, defval=false)
showSMA20       = input(title="Show SMA -20", type=input.bool, defval=false)
showSMA50       = input(title="Show SMA-50", type=input.bool, defval=false)
showSMA100      = input(title="Show SMA-100", type=input.bool, defval=false)
showwMA9        = input(title="Show WMA-9", type=input.bool, defval=false)
showwMA20       = input(title="Show WMA-20", type=input.bool, defval=false)
showwMA50       = input(title="Show WMA-50", type=input.bool, defval=false)
showwMA100      = input(title="Show WMA-100", type=input.bool, defval=false)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// EMA - 9/20/50/100 ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
EMA9_Len        = input(9, minval=1, title="EMA9_Length")
//EMA9_src      = input(close, title="EMA9_Source")
//EMA9_offset   = input(title="EMA9_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
EMA9_out        = ema(close, EMA9_Len)
plot(showEMA9 ? EMA9_out:na, title="EMA9", color=color.yellow, offset=0)

EMA20_Len       = input(20, minval=1, title="EMA20_Length")
//EMA20_src     = input(close, title="EMA20_Source")
//EMA20_offset  = input(title="EMA20_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
EMA20_out       = ema(close, EMA20_Len)
plot(showEMA20 ? EMA20_out:na, title="EMA20", color=color.blue, offset=0)

EMA50_Len       = input(50, minval=1, title="EMA50_Length")
//EMA50_src     = input(close, title="EMA50_Source")
//EMA50_offset  = input(title="EMA50_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
EMA50_out       = ema(close, EMA50_Len)
plot(showEMA50 ? EMA50_out:na, title="EMA50", color=color.fuchsia, offset=0)

EMA100_Len       = input(100, minval=1, title="EMA100_Length")
//EMA100_src     = input(close, title="EMA100_Source")
//EMA100_offset  = input(title="EMA100_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
EMA100_out       = ema(close, EMA100_Len)
plot(showEMA100 ? EMA100_out:na, title="EMA100", color=color.aqua, offset=0)


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// SMA - 9/20/50/100 ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SMA9_Len        = input(9, minval=1, title="SMA9_Length")
//SMA9_src     = input(close, title="SMA9_Source")
//SMA9_offset  = input(title="SMA9_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
SMA9_out        = sma(close, SMA9_Len)
plot(showSMA9 ? SMA9_out:na, title="SMA9", color=color.green, offset=0) 

SMA20_Len       = input(20, minval=1, title="SMA20_Length")
//SMA20_src    = input(close, title="SMA20_Source")
//SMA20_offset = input(title="SMA20_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
SMA20_out       = sma(close, SMA20_Len)
plot(showSMA20 ? SMA20_out:na, title="SMA20", color=color.red, offset=0) 

SMA50_Len       = input(50, minval=1, title="SMA50_Length")
//SMA50_src    = input(close, title="SMA50_Source")
//SMA50_offset = input(title="SMA50_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
SMA50_out       = sma(close, SMA50_Len)
plot(showSMA50 ? SMA50_out:na, title="SMA50", color=color.olive, offset=0) 

SMA100_Len       = input(100, minval=1, title="SMA100_Length")
//SMA100_src    = input(close, title="SMA100_Source")
//SMA100_offset = input(title="SMA100_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
SMA100_out       = sma(close, SMA100_Len)
plot(showSMA100 ? SMA100_out:na, title="SMA100", color=color.maroon, offset=0)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////// WMA - 9/20/50/100 ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

wMA9_Len        = input(9, minval=1, title="wMA9_Length")
//wMA9_src     = input(close, title="wMA9_Source")
//wMA9_offset  = input(title="wMA9_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
wMA9_out        = wma(close, wMA9_Len)
plot(showwMA9 ? wMA9_out:na, title="wMA9", color=color.navy, offset=0) 

wMA20_Len        = input(20, minval=1, title="wMA20_Length")
//wMA20_src     = input(close, title="wMA20_Source")
//wMA20_offset  = input(title="wMA20_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
wMA20_out        = wma(close, wMA20_Len)
plot(showwMA20 ? wMA20_out:na, title="wMA20", color=color.olive, offset=0) 

wMA50_Len        = input(50, minval=1, title="wMA50_Length")
//wMA50_src     = input(close, title="wMA50_Source")
//wMA50_offset  = input(title="wMA50_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
wMA50_out        = wma(close, wMA50_Len)
plot(showwMA50 ? wMA50_out:na, title="wMA50", color=color.purple, offset=0) 

wMA100_Len        = input(100, minval=1, title="wMA100_Length")
//wMA100_src     = input(close, title="wMA100_Source")
//wMA100_offset  = input(title="wMA100_Offset", type=input.integer, defval=0, minval=-500, maxval=500)
wMA100_out        = wma(close, wMA100_Len)
plot(showwMA100 ? wMA100_out:na, title="wMA100", color=color.gray, offset=0) 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////// VWAP /////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//vwaplength    = input(title="VWAP Length", type=input.integer, defval=1)
//cvwap         = ema(vwap,vwaplength)
cvwap1          = vwap(hlc3)
plotvwap        = plot(showVWAP ? cvwap1 : na,title="VWAP",color=color.black, transp=0, linewidth=2)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////// VWMA /////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
vwma_length     = 20            //input(title="VWMA Length", type=input.integer, defval=1)
vwma_1          = vwma(close,vwma_length)
plotvwma        = plot(showVWMA ? vwma_1 : na, title="VWMA", color=color.blue, transp=0, linewidth=2)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////// PARABOLIC SAR //////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
start           = 0.02          //input(0.02)
increment       = 0.02          //input(0.02)
maximum         = 0.2           //input(0.2, "Max Value")
psar_out        = sar(start, increment, maximum)
plot(showPSAR ? psar_out : na, "ParabolicSAR", style=plot.style_cross, color=#2196f3)



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// BOLLINGER BAND////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
length          = 20                //input(20, minval=1)
src             = close             //input(close, title="BB_Source")
mult            = 2                 //input(2.0, minval=0.001, maxval=50, title="BB_StdDev")
basis           = sma(src, length)
dev             = mult * stdev(src, length)
upper           = basis + dev
lower           = basis - dev
p1              = plot(showBB ? upper : na, "Upper", color=color.teal, editable=false)
p2              = plot(showBB ? lower: na, "Lower", color=color.teal, editable=false)
plot(showBB ? basis : na, "Basis", color=#872323, editable=false)
fill(p1, p2, title = "Background", color=#198787, transp=95)


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// CENTRAL PIVOT RANGE (CPR) //////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
res             = input(title="Resolution", type=input.resolution, defval="D")
res1            = input(title="Resolution", type=input.resolution, defval="W")
res2            = input(title="Resolution", type=input.resolution, defval="M")
H               = security(syminfo.tickerid, res, high[1],   barmerge.gaps_off, barmerge.lookahead_on)
L               = security(syminfo.tickerid, res, low[1],    barmerge.gaps_off, barmerge.lookahead_on)
C               = security(syminfo.tickerid, res, close[1],  barmerge.gaps_off, barmerge.lookahead_on)
WH              = security(syminfo.tickerid, res1, high[1],  barmerge.gaps_off, barmerge.lookahead_on)
WL              = security(syminfo.tickerid, res1, low[1],   barmerge.gaps_off, barmerge.lookahead_on)
WC              = security(syminfo.tickerid, res1, close[1], barmerge.gaps_off, barmerge.lookahead_on)
MH              = security(syminfo.tickerid, res2, high[1],  barmerge.gaps_off, barmerge.lookahead_on)
ML              = security(syminfo.tickerid, res2, low[1],   barmerge.gaps_off, barmerge.lookahead_on)
MC              = security(syminfo.tickerid, res2, close[1], barmerge.gaps_off, barmerge.lookahead_on)
TTH              = security(syminfo.tickerid, res, high,  barmerge.gaps_off, barmerge.lookahead_on)
TTL              = security(syminfo.tickerid, res, low,   barmerge.gaps_off, barmerge.lookahead_on)
TTC              = security(syminfo.tickerid, res, close, barmerge.gaps_off, barmerge.lookahead_on)

PP              = (H + L + C) / 3
TC              = (H + L)/2
BC              = (PP - TC) + PP
R1              = (PP * 2) - L
R2              = PP + (H - L)
R3              = H + 2*(PP - L)
R4              = PP * 3 + (H - 3 * L)
S1              = (PP * 2) - H
S2              = PP - (H - L)
S3              = L - 2*(H - PP)
S4              = PP*3 - (3*H - L)
WPP             = (WH + WL + WC)/3
WTC             = (WH + WL)/2
WBC             = (WPP - WTC) + WPP
MPP             = (MH + ML + MC)/3
MTC             = (MH + ML)/2
MBC             = (MPP - MTC) + MPP
TOPP             = (TTH + TTL + TTC)/3
TOTC             = (TTH + TTL)/2
TOBC             = (TOPP - TOTC) + TOPP
TR1              = (TOPP * 2) - TTL
TR2              = TOPP + (TTH - TTL)
TS1              = (TOPP * 2) - TTH
TS2              = TOPP - (TTH - TTL)
plot(showpivot ? PP : na, title="PP", style=plot.style_circles, color=color.orange, linewidth=2)
plot(showpivot ? TC : na, title="TC", style=plot.style_circles, color=color.blue,   linewidth=2)
plot(showpivot ? BC : na, title="BC", style=plot.style_circles, color=color.blue,   linewidth=2)

plot(showpivot ? WPP : na, title="WPP", style=plot.style_stepline, color=color.black, linewidth=2)
plot(showpivot ? WTC : na, title="WTC", style=plot.style_stepline, color=color.black,   linewidth=2)
plot(showpivot ? WBC : na, title="WBC", style=plot.style_stepline, color=color.black,   linewidth=2)

plot(showpivot ? MPP : na, title="MPP", style=plot.style_stepline, color=color.black, linewidth=3)
plot(showpivot ? MTC : na, title="MTC", style=plot.style_stepline, color=color.black,   linewidth=3)
plot(showpivot ? MBC : na, title="MBC", style=plot.style_stepline, color=color.black,   linewidth=3)

plot(showpivot ? S1 : na, title="S1", style=plot.style_stepline, color=color.black,  linewidth=1)
plot(showpivot ? S2 : na, title="S2", style=plot.style_stepline, color=color.black,  linewidth=1)
plot(showpivot ? S3 : na, title="S3", style=plot.style_stepline, color=color.black,  linewidth=1)
plot(showpivot ? S4 : na, title="S4", style=plot.style_stepline, color=color.black,  linewidth=1)

plot(showpivot ? R1 : na, title="R1", style=plot.style_stepline, color=color.black,  linewidth=1)
plot(showpivot ? R2 : na, title="R2", style=plot.style_stepline, color=color.black,  linewidth=1)
plot(showpivot ? R3 : na, title="R3", style=plot.style_stepline, color=color.black,  linewidth=1)
plot(showpivot ? R4 : na, title="R4", style=plot.style_stepline, color=color.black,  linewidth=1)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////// PREVIOUS DAY /////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
prevDayHigh     = security(syminfo.tickerid, 'D', high[1], lookahead=true)
prevDayLow      = security(syminfo.tickerid, 'D', low[1], lookahead=true)
plot( showpivot and prevDayHigh ? prevDayHigh : na, title="Prev Day High", style=plot.style_stepline, linewidth=1, color=color.red, transp=0)
plot( showpivot and prevDayLow ? prevDayLow  :  na, title="Prev Day Low", style=plot.style_stepline, linewidth=1, color=color.green, transp=0)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////// PREVIOUS WEEKLY  ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
prevWeekHigh     = security(syminfo.tickerid, 'W', high[1], lookahead=true)
prevWeekLow      = security(syminfo.tickerid, 'W', low[1], lookahead=true)
plot( showpivot and prevWeekHigh ? prevWeekHigh : na, title="Prev Week High", style=plot.style_stepline, linewidth=2, color=color.red, transp=0)
plot( showpivot and prevWeekLow ? prevWeekLow  :  na, title="Prev Week Low", style=plot.style_stepline, linewidth=2, color=color.green, transp=0)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////// PREVIOUS MONTH /////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
prevMonthHigh    = security(syminfo.tickerid, 'M', high[1], lookahead=true)
prevMonthLow     = security(syminfo.tickerid, 'M', low[1], lookahead=true)
plot( showpivot and prevMonthHigh ? prevMonthHigh : na, title="Prev Month High", style=plot.style_stepline, linewidth=3, color=color.red, transp=0)
plot( showpivot and prevMonthLow ? prevMonthLow  :  na, title="Prev Month Low", style=plot.style_stepline, linewidth=3, color=color.green, transp=0)



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////// NOT NECESSARY //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// colours for the chart 
//col0            = #6666ff 
//col1            = #ebdc87
//col2            = #ffa36c
//col3            = #d54062
//colD            = #799351
//plotF = input(defval=false, title="Plot 0.236", type=input.bool)
//supp0 = (PP - (0.236 * (H - L))) 
//supp1 = (PP - (0.382 * (H - L))) 
//supp2 = (PP - (0.618 * (H - L))) 
//supp3 = (PP - (1 * (H - L))) 
//res0 = (PP + (0.236 * (H - L)))
//res01 = (PP + (0.382 * (H - L)))
//res02 = (PP + (0.618 * (H - L)))
//res03 = (PP + (1 * (H - L)))
//plot(plotF ? supp0 : na, title="0.236", style=plot.style_stepline, color=color.orange , linewidth=1)
//plot(plotF ? res0 : na, title="0.236", style=plot.style_stepline, color=color.orange,  linewidth=1)