DIVISLAB trade ideas
Magic
//@version=3
//
study(title = "Magic Trading Tool", shorttitle = "TTSS", overlay = true)
// === INPUTS ===
ShowPAC_ = input(true, title="Show Price Action Channel (PAC)")
scolor = input(true, title="Show coloured Bars close relative on PAC")
HiLoLen = input(10,minval=2,title="High Low PAC Length")
ShowPACexit = input(false, title="Show PAC Swing Alerts")
UseBigArrows = input(false, title="Use Big Arrows for Swing Alerts")
filterEMA200 = input(true, title="Filter PAC Alerts with 200ema")
ShowEMA12_Channel= input(true)
ShowEMA36_Ribbon = input(true)
ShowPAC = HiLoLen>30 ? ShowEMA36_Ribbon? false: ShowPAC_: ShowEMA12_Channel? false : ShowPAC_
ShowPivots = input(true)
ShowPivotLabels = input(true)
// Disable Fractal drawing if Pivots enabled
ShowHHLL_ = input(false)
ShowHHLL = ShowPivots?false:ShowHHLL_
ShowFractals_= input(true)
ShowFractals = ShowPivots?false:ShowFractals_
ShowFractalLevels =input(false)
filterBW_ = input(false, title="Filter for Pristine (Ideal) Fractals")
filterBW = ShowPivots?true:filterBW_
DodgerBlue = #1E90FF
close_ = close //security(ticker, period, close, barmerge.gaps_off, barmerge.lookahead_on)
open_ = open //security(ticker, period, open, barmerge.gaps_off, barmerge.lookahead_on)
high_ = high //security(ticker, period, high, barmerge.gaps_off, barmerge.lookahead_on)
low_ = low //security(ticker, period, low, barmerge.gaps_off, barmerge.lookahead_on)
exitClose = close_ //UseHAexit ? security(heikinashi(tickerid), period, close) : close_
exitOpen = open_ //UseHAexit ? security(heikinashi(tickerid), period, open) : open_
isRegularFractal(mode) =>
ret = mode == 1 ? high_ < high_ and high_ < high_ and high_ > high_ and high_ > high_ :
mode == -1 ? low_ > low_ and low_ > low_ and low_ < low_ and low_ < low_ : false
isBWFractal(mode) =>
ret = mode == 1 ? high_ < high_ and high_ < high_ and high_ > high_ and high_ > high_ :
mode == -1 ? low_ > low_ and low_ > low_ and low_ < low_ and low_ < low_ : false
// ||-----------------------------------------------------------------------------------------------------||
// MA Colour finder for EMA Ribbon plot.
maColor(maBase, ma, maRef) =>
change(ma)>=0 and maBase>maRef ? teal
:change(ma)<0 and maBase>maRef ? maroon
:change(ma)<=0 and maBase=0 and maBase=pacU? green : close<=pacL? red : gray
barcolor(scolor?bColour:na, title = "Bar Colours")
ema05=plot(ShowEMA12_Channel?EMA05:na, color=white,linewidth=1,transp=92,title="EMA05")
ema11=plot(ShowEMA12_Channel?EMA11:na, color=blue,linewidth=1,transp=92,title="EMA11")
fill(ema05,ema11, color=gray,transp=92,title="Fill EMA5-12")
//
emaFast = isintraday? interval==1? EMA75 : EMA89 : EMA89
emaMedium = isintraday? interval==1? EMA180 : EMA200 : EMA200
emaSlow = isintraday? interval==1? EMA540 : EMA633 : EMA633
plot(emaFast, color=green,linewidth=3,transp=20,title="EMA fast")
plot(emaMedium, color=orange,linewidth=3,transp=20,title="EMA medium")
plot(emaSlow, color=yellow,linewidth=3,transp=20,title="EMA slow")
plot( ShowEMA36_Ribbon?EMA12:na, color=maColor(EMA12,EMA12,EMA36), style=line, title="MA12", linewidth=1,transp=20)
plot( ShowEMA36_Ribbon?EMA15:na, color=maColor(EMA12,EMA15,EMA36), style=line, title="MA15", linewidth=1,transp=20)
plot( ShowEMA36_Ribbon?EMA18:na, color=maColor(EMA12,EMA18,EMA36), style=line, title="MA18", linewidth=1,transp=20)
plot( ShowEMA36_Ribbon?EMA21:na, color=maColor(EMA12,EMA21,EMA36), style=line, title="MA21", linewidth=1,transp=20)
plot( ShowEMA36_Ribbon?EMA24:na, color=maColor(EMA12,EMA24,EMA36), style=line, title="MA24", linewidth=1,transp=20)
plot( ShowEMA36_Ribbon?EMA27:na, color=maColor(EMA12,EMA27,EMA36), style=line, title="MA27", linewidth=1,transp=20)
plot( ShowEMA36_Ribbon?EMA30:na, color=maColor(EMA12,EMA30,EMA36), style=line, title="MA30", linewidth=1,transp=20)
plot( ShowEMA36_Ribbon?EMA33:na, color=maColor(EMA12,EMA33,EMA36), style=line, title="MA33", linewidth=1,transp=20)
plot( EMA36, color=ShowEMA36_Ribbon?maColor(EMA12,EMA36,EMA36):red, style=line, title="MA36", linewidth=1,transp=20)
filteredtopf = filterBW ? isRegularFractal(1) : isBWFractal(1)
filteredbotf = filterBW ? isRegularFractal(-1) : isBWFractal(-1)
topfractals = na
botfractals = na
topfractals := filteredtopf ? high_ : topfractals
botfractals := filteredbotf ? low_ : botfractals
topfcolor = na
botfcolor = na
topfcolor := topfractals != topfractals ? na : green
botfcolor := botfractals != botfractals ? na : red
plot(ShowFractalLevels? topfractals : na, color=topfcolor, transp=0, linewidth=2)
plot(ShowFractalLevels? botfractals : na, color=botfcolor, transp=0, linewidth=2)
higherhigh = filteredtopf == false ? false : ( valuewhen(filteredtopf == true, high_ , 1) < valuewhen(filteredtopf == true, high_ , 0) and
(ShowPivots or valuewhen(filteredtopf == true, high_ , 2) < valuewhen(filteredtopf == true, high_ , 0)))
lowerhigh = filteredtopf == false ? false : ( valuewhen(filteredtopf == true, high_ , 1) > valuewhen(filteredtopf == true, high_ , 0) and
(ShowPivots or valuewhen(filteredtopf == true, high_ , 2) > valuewhen(filteredtopf == true, high_ , 0)))
higherlow = filteredbotf == false ? false : ( valuewhen(filteredbotf == true, low_ , 1) < valuewhen(filteredbotf == true, low_ , 0) and
(ShowPivots or valuewhen(filteredbotf == true, low_ , 2) < valuewhen(filteredbotf == true, low_ , 0)))
lowerlow = filteredbotf == false ? false : ( valuewhen(filteredbotf == true, low_ , 1) > valuewhen(filteredbotf == true, low_ , 0) and
(ShowPivots or valuewhen(filteredbotf == true, low_ , 2) > valuewhen(filteredbotf == true, low_ , 0)))
// If selected show HH/LL on top/below candles.
isup = exitClose>exitOpen and exitClose>pacU and exitClose emaMedium)
isdown = exitClosepacL and (not filterEMA200 or pacC<emaMedium)
up_alert = 0
dn_alert = 0
up_alert := isup ? na(up_alert ) ? 1 : up_alert +1 : 0
dn_alert := isdown ? na(dn_alert ) ? 1 : dn_alert +1 : 0
plotarrow(ShowPACexit and UseBigArrows? up_alert ==1? 1 : dn_alert ==1? -1 : na : na, colorup=aqua, colordown=fuchsia, transp=20,minheight=10,maxheight=60, title="SCALPSWING Alert Arrows")
plotshape(ShowPACexit and not UseBigArrows? up_alert ==1? true : na : na, title='TTSS Buy Arrow', location=location.belowbar, color=green, style=shape.arrowup, text="BUY", textcolor=green,transp=0)
plotshape(ShowPACexit and not UseBigArrows? dn_alert ==1? true : na : na, title='TTSS Sell Arrow', location=location.abovebar, color=red, style=shape.arrowdown, text="SELL",textcolor=red,transp=0)
// generate an alert if required.
alertcondition(up_alert==1, title="TTSS alert Up", message="SWING_UP")
alertcondition(dn_alert==1, title="TTSS alert Down", message="SWING_DN")