Wolf EMA & OHL & SIGNALS
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © WoLf4EvEr
// 

//@version=4
study(title="Wolf EMA & OHL & SIGNALS", overlay=true)

EMASMA  = input(defval="EMA", title = 'Type MA', inline="01", options=["EMA", "SMA"])

var GRP1 = "EMA/SMA Value & Style"
ShowMA1  = input(true, title='Show     ', type = input.bool, inline="01", group=GRP1)
EMA1    = input(   5, title = 'MA 1', type = input.integer, inline="01", group = GRP1)
colEMA1  = input( #FC3A4B, title = '    Color', type = input.color, inline="01", group = GRP1)
ShowMA2  = input(true, title='Show     ', type = input.bool, inline="02", group=GRP1)
EMA2    = input(  10, title = 'MA 2', type = input.integer, inline="02", group = GRP1)
colEMA2  = input( #FFED5E, title = '    Color', type = input.color, inline="02", group = GRP1)
ShowMA3  = input(true, title='Show     ', type = input.bool, inline="03", group=GRP1)
EMA3    = input(  50, title = 'MA 3', type = input.integer, inline="03", group = GRP1)
colEMA3  = input( #579AF3, title = '    Color', type = input.color, inline="03", group = GRP1)
ShowMA4  = input(true, title='Show     ', type = input.bool, inline="04", group=GRP1)
EMA4    = input( 100, title = 'MA 4', type = input.integer, inline="04", group = GRP1)
colEMA4  = input( #673AB7, title = '    Color', type = input.color, inline="04", group = GRP1)
ShowMA5  = input(true, title='Show     ', type = input.bool, inline="05", group=GRP1)
EMA5    = input( 200, title = 'MA 5', type = input.integer, inline="05", group = GRP1)
colEMA5  = input( #A022AD, title = '    Color', type = input.color, inline="05", group = GRP1)


var GRP22 = "EMA/SMA Style Day"
ShowMAD = input(true, title='Show    ', type = input.bool, inline="01", group=GRP22)
styleOption = input("dashed (╌)", type=input.string, title="Style", inline="01", group = GRP22, options=["solid (─)", "dotted (┈)", "dashed (╌)","arrow left (←)", "arrow right (→)", "arrows both (↔)"])

lineStyle = styleOption == "dotted (┈)" ? line.style_dotted :
     styleOption == "dashed (╌)" ? line.style_dashed :
     styleOption == "arrow left (←)" ? line.style_arrow_left :
     styleOption == "arrow right (→)" ? line.style_arrow_right :
     styleOption == "arrows both (↔)" ? line.style_arrow_both :
         line.style_solid
lineWidht = input( 1, title = '    Width', type = input.integer, inline="01",group = GRP22)

var GRP3 = 'Open High Low Label'
WEEK    = input(false,   title='Show Week Open-High-Low', type = input.bool, inline="01", group=GRP3)
c_High  = input(#00CB84, title='HIGH_  ', type = input.color, inline="02", group=GRP3)
c_Open  = input(#FFFFFF, title='OPEN   ', type = input.color, inline="03", group=GRP3)
c_Low   = input(#FF0000, title='LOW_   ', type = input.color, inline="04",group=GRP3)
c_High1 = input(#00CB84, title='HIGH -1', type = input.color, inline="02", group=GRP3)
c_Open1 = input(#FFFFFF, title='OPEN -1', type = input.color, inline="03", group=GRP3)
c_Low1  = input(#FF0000, title='LOW_ -1', type = input.color, inline="04",group=GRP3)
OFFSET  = input(10,      title='Margin Label',  type = input.integer, inline="05", group=GRP3)

var GRP9 = "Alert EMA"
alertEMA1 = input(false, "Alert MA 1", inline="01", group = GRP9)
alertEMA2 = input(false, "Alert MA 2", inline="01", group = GRP9)
alertEMA3 = input(false, "Alert MA 3", inline="01", group = GRP9)
alertEMA4 = input(false, "Alert MA 4", inline="01", group = GRP9)
alertEMA5 = input(false, "Alert MA 5", inline="01", group = GRP9)
alertEMA6 = input(false, "Alert MA 1D", inline="02", group = GRP9)
alertEMA7 = input(false, "Alert MA 2D", inline="02", group = GRP9)
alertEMA8 = input(false, "Alert MA 3D", inline="02", group = GRP9)
alertEMA9 = input(false, "Alert MA 4D", inline="02", group = GRP9)
//alertEMA10 = input(false, "Alert EMA 10", inline="04", group = GRP1)

var GRP4 = "Shimano"
alertShimano = input(false, "Alert Shimano", inline="01", group = GRP4)
ShimanoLength = input(10, title = '  Shimano Length', type = input.integer, inline="01", group = GRP4)

var GRP5 = "Viagra"
alertViagra = input(false, "Alert Viagra", inline="01", group = GRP5)
ViagraLength = input(20, title = '  Viagra Length', type = input.integer, inline="01", group = GRP5)

var GRP6 = "Anti-crossing"
alertTrend = input(false, "Alert Anti-crossing", inline="01", group = GRP6)
//TrendLength = input(30, title = '  Trend Length', type = input.integer, inline="01", group = GRP6)

var GRP7 = "Cross"
alertCross = input(false, "Alert Crossing", inline="01", group = GRP7)
//CrossLength = input(30, title = '  Cross Length', type = input.integer, inline="01", group = GRP7)

var GRP8 = "BUD"
alertBud = input(false, "Alert BUD", group = GRP8)



// Var EMA
valEMA1 = EMASMA=="EMA" ? ema(close,EMA1):sma(close,EMA1)
valEMA2 = EMASMA=="EMA" ? ema(close,EMA2):sma(close,EMA2) //ema(close,EMA2)   
valEMA3 = EMASMA=="EMA" ? ema(close,EMA3):sma(close,EMA3)  
valEMA4 = EMASMA=="EMA" ? ema(close,EMA4):sma(close,EMA4) 
valEMA5 = EMASMA=="EMA" ? ema(close,EMA5):sma(close,EMA5)


// Draw EMA

plotEMA1 = plot(ShowMA1?valEMA1:na, title = 'MA 1', color = colEMA1, linewidth=1)
plotEMA2 = plot(ShowMA2?valEMA2:na, title = 'MA 2', color = colEMA2, linewidth=1)
plotEMA3 = plot(ShowMA3?valEMA3:na, title = 'MA 3', color = colEMA3, linewidth=2)
plotEMA4 = plot(ShowMA4?valEMA4:na, title = 'MA 4', color = colEMA4, linewidth=2) //display=display.none
plotEMA5 = plot(ShowMA5?valEMA5:na, title = 'MA 5', color = colEMA5, linewidth=3)


var ltime = " [D]"
isNewDay = time("D") != time("D")[1]
isNewWeek = time("W") != time("W")[1]

valEMA6 =security(syminfo.tickerid, "D", EMASMA=="EMA" ? ema(close, EMA1):sma(close, EMA1), barmerge.gaps_off, barmerge.lookahead_on)
valEMA7 =security(syminfo.tickerid, "D", EMASMA=="EMA" ? ema(close, EMA2):sma(close, EMA2), barmerge.gaps_off, barmerge.lookahead_on)
valEMA8 =security(syminfo.tickerid, "D", EMASMA=="EMA" ? ema(close, EMA3):sma(close, EMA3), barmerge.gaps_off, barmerge.lookahead_on)
valEMA9 =security(syminfo.tickerid, "D", EMASMA=="EMA" ? ema(close, EMA4):sma(close, EMA4), barmerge.gaps_off, barmerge.lookahead_on)
valEMA10=security(syminfo.tickerid, "D", EMASMA=="EMA" ? ema(close, EMA5):sma(close, EMA5), barmerge.gaps_off, barmerge.lookahead_on)
valEMA6W =security(syminfo.tickerid, "W", EMASMA=="EMA" ? ema(close, EMA1):sma(close, EMA1), barmerge.gaps_off, barmerge.lookahead_on)
valEMA7W =security(syminfo.tickerid, "W", EMASMA=="EMA" ? ema(close, EMA2):sma(close, EMA2), barmerge.gaps_off, barmerge.lookahead_on)
valEMA8W =security(syminfo.tickerid, "W", EMASMA=="EMA" ? ema(close, EMA3):sma(close, EMA3), barmerge.gaps_off, barmerge.lookahead_on)
valEMA9W =security(syminfo.tickerid, "W", EMASMA=="EMA" ? ema(close, EMA4):sma(close, EMA4), barmerge.gaps_off, barmerge.lookahead_on)
valEMA10W=security(syminfo.tickerid, "W", EMASMA=="EMA" ? ema(close, EMA5):sma(close, EMA5), barmerge.gaps_off, barmerge.lookahead_on)

if timeframe.isintraday and ShowMAD
    var line L_EMA6 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.none, color=colEMA1, style=lineStyle, width=lineWidht)
    var line L_EMA7 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.none, color=colEMA2, style=lineStyle, width=lineWidht)
    var line L_EMA8 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.none, color=colEMA3, style=lineStyle, width=lineWidht)
    var line L_EMA9 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.none, color=colEMA4, style=lineStyle, width=lineWidht)
    var line L_EMA10= line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.none, color=colEMA5, style=lineStyle, width=lineWidht)
    
    if isNewDay
        L_EMA6 := line.new(bar_index, valEMA6[1], bar_index+1, valEMA6[1], extend=extend.none, color=colEMA1, style=lineStyle, width=lineWidht)
        L_EMA7 := line.new(bar_index, valEMA7[1], bar_index+1, valEMA7[1], extend=extend.none, color=colEMA2, style=lineStyle, width=lineWidht)
        L_EMA8 := line.new(bar_index, valEMA8[1], bar_index+1, valEMA8[1], extend=extend.none, color=colEMA3, style=lineStyle, width=lineWidht)
        L_EMA9 := line.new(bar_index, valEMA9[1], bar_index+1, valEMA9[1], extend=extend.none, color=colEMA4, style=lineStyle, width=lineWidht)
        L_EMA10:= line.new(bar_index,valEMA10[1], bar_index+1,valEMA10[1], extend=extend.none, color=colEMA5, style=lineStyle, width=lineWidht)
    if not isNewDay
        line.set_x2(L_EMA6, bar_index)
        line.set_y2(L_EMA6, valEMA6[0])
        line.set_x2(L_EMA7, bar_index)
        line.set_y2(L_EMA7, valEMA7[0])
        line.set_x2(L_EMA8, bar_index)
        line.set_y2(L_EMA8, valEMA8[0])
        line.set_x2(L_EMA9, bar_index)
        line.set_y2(L_EMA9, valEMA9[0])
        line.set_x2(L_EMA10, bar_index)
        line.set_y2(L_EMA10, valEMA10[0])
   
    labelEMA6 = label.new( bar_index+2,  valEMA6, EMASMA+tostring(EMA1)+ltime, textcolor=colEMA1, size=size.small, style=label.style_none)
    label.delete(labelEMA6[1])
    labelEMA7 = label.new( bar_index+2,  valEMA7, EMASMA+tostring(EMA2)+ltime, textcolor=colEMA2, size=size.small, style=label.style_none)
    label.delete(labelEMA7[1])
    labelEMA8 = label.new( bar_index+2,  valEMA8, EMASMA+tostring(EMA3)+ltime, textcolor=colEMA3, size=size.small, style=label.style_none)
    label.delete(labelEMA8[1])
    labelEMA9 = label.new( bar_index+2,  valEMA9, EMASMA+tostring(EMA4)+ltime, textcolor=colEMA4, size=size.small, style=label.style_none)
    label.delete(labelEMA9[1])
    labelEMA10= label.new( bar_index+2,  valEMA10, EMASMA+tostring(EMA5)+ltime, textcolor=colEMA5, size=size.small, style=label.style_none)
    label.delete(labelEMA10[1])

if not timeframe.isintraday and ShowMAD and timeframe.isdaily
    ltime := " [W]"
    var line L_EMA6 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.none, color=colEMA1, style=lineStyle, width=lineWidht)
    var line L_EMA7 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.none, color=colEMA2, style=lineStyle, width=lineWidht)
    var line L_EMA8 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.none, color=colEMA3, style=lineStyle, width=lineWidht)
    var line L_EMA9 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.none, color=colEMA4, style=lineStyle, width=lineWidht)
    var line L_EMA10= line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.none, color=colEMA5, style=lineStyle, width=lineWidht)
    
    if isNewWeek
        L_EMA6 := line.new(bar_index, valEMA6W[1], bar_index+1, valEMA6W[1], extend=extend.none, color=colEMA1, style=lineStyle, width=lineWidht)
        L_EMA7 := line.new(bar_index, valEMA7W[1], bar_index+1, valEMA7W[1], extend=extend.none, color=colEMA2, style=lineStyle, width=lineWidht)
        L_EMA8 := line.new(bar_index, valEMA8W[1], bar_index+1, valEMA8W[1], extend=extend.none, color=colEMA3, style=lineStyle, width=lineWidht)
        L_EMA9 := line.new(bar_index, valEMA9W[1], bar_index+1, valEMA9W[1], extend=extend.none, color=colEMA4, style=lineStyle, width=lineWidht)
        L_EMA10:= line.new(bar_index,valEMA10W[1], bar_index+1,valEMA10W[1], extend=extend.none, color=colEMA5, style=lineStyle, width=lineWidht)
    if not isNewWeek
        line.set_x2(L_EMA6, bar_index)
        line.set_y2(L_EMA6, valEMA6W[0])
        line.set_x2(L_EMA7, bar_index)
        line.set_y2(L_EMA7, valEMA7W[0])
        line.set_x2(L_EMA8, bar_index)
        line.set_y2(L_EMA8, valEMA8W[0])
        line.set_x2(L_EMA9, bar_index)
        line.set_y2(L_EMA9, valEMA9W[0])
        line.set_x2(L_EMA10, bar_index)
        line.set_y2(L_EMA10, valEMA10W[0])
   
    labelEMA6 = label.new( bar_index+2,  valEMA6W, EMASMA+tostring(EMA1)+ltime, textcolor=colEMA1, size=size.small, style=label.style_none)
    label.delete(labelEMA6[1])
    labelEMA7 = label.new( bar_index+2,  valEMA7W, EMASMA+tostring(EMA2)+ltime, textcolor=colEMA2, size=size.small, style=label.style_none)
    label.delete(labelEMA7[1])
    labelEMA8 = label.new( bar_index+2,  valEMA8W, EMASMA+tostring(EMA3)+ltime, textcolor=colEMA3, size=size.small, style=label.style_none)
    label.delete(labelEMA8[1])
    labelEMA9 = label.new( bar_index+2,  valEMA9W, EMASMA+tostring(EMA4)+ltime, textcolor=colEMA4, size=size.small, style=label.style_none)
    label.delete(labelEMA9[1])
    labelEMA10= label.new( bar_index+2,  valEMA10W, EMASMA+tostring(EMA5)+ltime, textcolor=colEMA5, size=size.small, style=label.style_none)
    label.delete(labelEMA10[1])


//----------- Allerts EMA -----------------
if crossover(close, valEMA1) and alertEMA1
    alert("OVER "+EMASMA+tostring(EMA1)+ltime, alert.freq_once_per_bar_close)
if crossunder(close, valEMA1) and alertEMA1
    alert("UNDER "+EMASMA+tostring(EMA1)+ltime, alert.freq_once_per_bar_close)

if crossover(close, valEMA2) and alertEMA2
    alert("OVER "+EMASMA+tostring(EMA2)+ltime, alert.freq_once_per_bar_close)
if crossunder(close, valEMA2) and alertEMA2
    alert("UNDER "+EMASMA+tostring(EMA2)+ltime, alert.freq_once_per_bar_close)
    
if crossover(close, valEMA3) and alertEMA3
    alert("OVER "+EMASMA+tostring(EMA3)+ltime, alert.freq_once_per_bar_close)
if crossunder(close, valEMA3) and alertEMA3
    alert("UNDER "+EMASMA+tostring(EMA3)+ltime, alert.freq_once_per_bar_close)
    
if crossover(close, valEMA4) and alertEMA4
    alert("OVER "+EMASMA+tostring(EMA4)+ltime, alert.freq_once_per_bar_close)
if crossunder(close, valEMA4) and alertEMA4
    alert("UNDER "+EMASMA+tostring(EMA4)+ltime, alert.freq_once_per_bar_close)
    
if crossover(close, valEMA5) and alertEMA5
    alert("OVER "+EMASMA+tostring(EMA5)+ltime, alert.freq_once_per_bar_close)
if crossunder(close, valEMA5) and alertEMA5
    alert("UNDER "+EMASMA+tostring(EMA5)+ltime, alert.freq_once_per_bar_close)
    
if crossover(close, valEMA6) and alertEMA6
    alert("OVER "+EMASMA+tostring(EMA1)+ltime, alert.freq_once_per_bar_close)
if crossunder(close, valEMA6) and alertEMA6
    alert("UNDER "+EMASMA+tostring(EMA1)+ltime, alert.freq_once_per_bar_close) 
    
if crossover(close, valEMA7) and alertEMA7
    alert("OVER "+EMASMA+tostring(EMA2)+ltime, alert.freq_once_per_bar_close)
if crossunder(close, valEMA7) and alertEMA7
    alert("UNDER "+EMASMA+tostring(EMA2)+ltime, alert.freq_once_per_bar_close)

if crossover(close, valEMA8) and alertEMA8
    alert("OVER "+EMASMA+tostring(EMA3)+ltime, alert.freq_once_per_bar_close)
if crossunder(close, valEMA8) and alertEMA8
    alert("UNDER "+EMASMA+tostring(EMA3)+ltime, alert.freq_once_per_bar_close)
    
if crossover(close, valEMA9) and alertEMA9
    alert("OVER "+EMASMA+tostring(EMA4)+ltime, alert.freq_once_per_bar_close)
if crossunder(close, valEMA9) and alertEMA9
    alert("UNDER "+EMASMA+tostring(EMA4)+ltime, alert.freq_once_per_bar_close)
    
//if crossover(close, valEMA10) and alertEMA10
//    alert("OVER EMA"+tostring(EMA10)+ltime, alert.freq_once_per_bar_close)
//if crossunder(close, valEMA10) and alertEMA10
//    alert("UNDER EMA"+tostring(EMA10)+ltime, alert.freq_once_per_bar_close)

//--------- Set Type Label -------------------
var label myLabelH    = label.new(na, na, "____________ HIGH [D] ___________", textcolor=c_High,  style=label.style_none, textalign = text.align_right )
var label myLabelO    = label.new(na, na, "____________ OPEN [D] ___________", textcolor=c_Open,  style=label.style_none, textalign = text.align_right )
var label myLabelL    = label.new(na, na, "_____________ LOW [D] ___________", textcolor=c_Low,   style=label.style_none, textalign = text.align_right )
var label myLabelH1   = label.new(na, na, "_____________________ HIGH [D-1] ", textcolor=c_High1, style=label.style_none, textalign = text.align_left )
var label myLabelO1   = label.new(na, na, "_____________________ OPEN [D-1] ", textcolor=c_Open1, style=label.style_none, textalign = text.align_right )
var label myLabelL1   = label.new(na, na, "______________________ LOW [D-1] ", textcolor=c_Low1,  style=label.style_none, textalign = text.align_right )
var label myLabelWH   = label.new(na, na, "_  _  _  _  _  _  _  _  _  _  _ HIGH [W]", textcolor=c_High,  style=label.style_none, textalign = text.align_left )
var label myLabelWO   = label.new(na, na, "_  _  _  _  _  _  _  _  _  _  _ OPEN [W]", textcolor=c_Open,  style=label.style_none, textalign = text.align_left )
var label myLabelWL   = label.new(na, na, "_  _  _  _  _  _  _  _  _  _  _ _LOW [W]", textcolor=c_Low,   style=label.style_none, textalign = text.align_left )
var label myLabelWH1  = label.new(na, na, "_  _  _  _  _  _  _  _  _  _  _ HIGH [W-1]", textcolor=c_High1, style=label.style_none, textalign = text.align_left )
var label myLabelWO1  = label.new(na, na, "_  _  _  _  _  _  _  _  _  _  _ OPEN [W-1]", textcolor=c_Open1, style=label.style_none, textalign = text.align_left )
var label myLabelWL1  = label.new(na, na, "_  _  _  _  _  _  _  _  _  _  _ _LOW [W-1]", textcolor=c_Low1,  style=label.style_none, textalign = text.align_left )

var line myLineH  = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.both, color=#00000000, style=line.style_solid, width=1)
var line myLineO  = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.both, color=#00000000, style=line.style_solid, width=1)
var line myLineL  = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.both, color=#00000000, style=line.style_solid, width=1)
var line myLineH1 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.both, color=#00000000, style=line.style_solid, width=1)
var line myLineO1 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.both, color=#00000000, style=line.style_solid, width=1)
var line myLineL1 = line.new(na, na, na, na, xloc=xloc.bar_time, extend=extend.both, color=#00000000, style=line.style_solid, width=1)

// Var OHL
day_high  = security(syminfo.tickerid, 'D', high[0])
day_open  = security(syminfo.tickerid, 'D', open[0])
day_low   = security(syminfo.tickerid, 'D', low[0] )
day_high1 = security(syminfo.tickerid, 'D', high[1])
day_open1 = security(syminfo.tickerid, 'D', open[1])
day_low1  = security(syminfo.tickerid, 'D', low[1] )

week_high  = security(syminfo.tickerid, 'W', high[0])
week_open  = security(syminfo.tickerid, 'W', open[0])
week_low   = security(syminfo.tickerid, 'W', low[0] )
week_high1 = security(syminfo.tickerid, 'W', high[1])
week_open1 = security(syminfo.tickerid, 'W', open[1])
week_low1  = security(syminfo.tickerid, 'W', low[1] )


dt = time - time[1]
F_Line(_line, _y) =>
    line.set_xy1(_line, time_close , _y)
    line.set_xy2(_line, time_close + 5, _y)

F_Label(_lab, _y, _set) =>
    label.set_y(_lab, _y)
    label.set_xloc(_lab,  time + _set * dt, xloc.bar_time)
    label.set_size(_lab, size.small)
    

// Draw Line & Label
if timeframe.isintraday
   
    F_Line(myLineH, day_high)
    line.set_color(myLineH,abs(((close[0] - day_high)/day_high)*100) < 2 ? c_High : #00000000)
    F_Line(myLineO, day_open)
    line.set_color(myLineO,abs(((close[0] - day_open)/day_open)*100) < 2 ? c_Open : #00000000)
    F_Line(myLineL, day_low)
    line.set_color(myLineL,abs(((close[0] - day_low)/day_low)*100) < 2 ? c_Low : #00000000)
    F_Line(myLineH1, day_high1)
    line.set_color(myLineH1,abs(((close[0] - day_high1)/day_high1)*100) < 2 ? c_High1 : #00000000)
    F_Line(myLineO1, day_open1)
    line.set_color(myLineO1,abs(((close[0] - day_open1)/day_open1)*100) < 2 ? c_Open1 : #00000000)
    F_Line(myLineL1, day_low1)
    line.set_color(myLineL1,abs(((close[0] - day_low1)/day_low1)*100) < 2 ? c_Low1 : #00000000)

    
    F_Label( myLabelH, day_high, OFFSET )
    F_Label( myLabelO, day_open, OFFSET )
    F_Label( myLabelL, day_low, OFFSET )
    F_Label( myLabelH1, day_high1, OFFSET )
    F_Label( myLabelO1, day_open1, OFFSET )
    F_Label( myLabelL1, day_low1, OFFSET )
 
if WEEK
    F_Label( myLabelWH, week_high, OFFSET )
    F_Label( myLabelWO, week_open, OFFSET )
    F_Label( myLabelWL, week_low, OFFSET )
    F_Label( myLabelWH1, week_high1, OFFSET )
    F_Label( myLabelWO1, week_open1, OFFSET )
    F_Label( myLabelWL1, week_low1, OFFSET )  
    
    
//--------------------------------------------------------
//|                       SIGNALS                        |
//--------------------------------------------------------

//---------------------- Shimano -------------------------
var shimano_count = 0
go_shimano_long = false
go_shimano_short = false 
var is_shimano_long = false
var is_shimano_short = false 

if (close[0] < valEMA5[0] and close[0] > valEMA3[0]) or (close[0] > valEMA5[0] and close[0] < valEMA3[0])
    shimano_count := shimano_count + 1

if shimano_count > ShimanoLength
    if close > valEMA5 and close > valEMA3 and not is_shimano_long
        go_shimano_long := true
        is_shimano_long := true
    if close < valEMA3  and close < valEMA5 and not is_shimano_short
        go_shimano_short := true
        is_shimano_short := true
        
if (valEMA1[0] > valEMA5[0] and valEMA1[0] > valEMA3[0]) or (valEMA1[0] < valEMA5[0] and valEMA1[0] < valEMA3[0])
    shimano_count := 0
    is_shimano_long := false
    is_shimano_short := false
    
plotshape(go_shimano_long,"Shimano Long", style=shape.arrowup, location=location.abovebar, text="▲ S", textcolor=#FFFFFF, color=#FFFFFF00)
if go_shimano_long and alertShimano
    alert("Shimano Long", alert.freq_once_per_bar_close)
    
plotshape(go_shimano_short,"Shimano Short", style=shape.arrowdown, location=location.belowbar, text="▼ S", textcolor=#FFFFFF, color=#FFFFFF00)
if go_shimano_short and alertShimano
    alert("Shimano Short", alert.freq_once_per_bar_close)


//---------------------- Viagra -------------------------
var viagra_long = 0
var viagra_short = 0
go_viagra_long = false
go_viagra_short = false 

// viagra LONG
if close[0] < valEMA2[0]
    viagra_long := viagra_long + 1

if viagra_long > ViagraLength
    if close[0] > valEMA2[0] 
        go_viagra_long := true

if close[0] > valEMA2[0]
    viagra_long := 0
    
// viagra SHORT
if close[0] > valEMA2[0]
    viagra_short := viagra_short + 1

if viagra_short > ViagraLength
    if close[0] < valEMA2[0] 
        go_viagra_short := true
        
if close[0] < valEMA2[0]
    viagra_short := 0
        
plotshape(go_viagra_long,"Viagra Long", style=shape.arrowup, location=location.abovebar, text="▲ V", textcolor=#FFFFFF, color=#FFFFFF00)
if go_viagra_long and alertViagra
    alert("viagra Long", alert.freq_once_per_bar_close)
    
plotshape(go_viagra_short,"Viagra Short", style=shape.arrowdown, location=location.belowbar, text="▼ V", textcolor=#FFFFFF, color=#FFFFFF00)
if go_viagra_short and alertViagra
    alert("Viagra Short", alert.freq_once_per_bar_close)



//---------------------- Cross -------------------------
go_cross_long = false
go_cross_short = false 
var is_cross_long = false
var is_cross_short = false


if crossover(valEMA1[0], valEMA3[0]) and  valEMA5[0] > valEMA3[0]
    is_cross_long := true

if crossunder(valEMA1[0], valEMA3[0]) and is_cross_long
    is_cross_long := false
    
if crossover(valEMA1[0], valEMA5[0]) and  valEMA5[0] > valEMA3[0] and is_cross_long
    go_cross_long := true
    
    
if crossunder(valEMA1[0], valEMA3[0]) and  valEMA5[0] < valEMA3[0]
    is_cross_short := true

if crossover(valEMA1[0], valEMA3[0]) and is_cross_short
    is_cross_short := false
    
if crossunder(valEMA1[0], valEMA5[0]) and  valEMA5[0] < valEMA3[0] and is_cross_short
    go_cross_short := true

        
plotshape(go_cross_long,"Cross Long", style=shape.arrowup, location=location.belowbar, text="▲ C", textcolor=#FFFFFF, color=#00FF0099)
if go_cross_long and alertCross
    alert("Cross Long", alert.freq_once_per_bar_close)
    
plotshape(go_cross_short,"Cross Short", style=shape.arrowdown, location=location.abovebar, text="▼ C", textcolor=#FFFFFF, color=#FF000099)
if go_cross_short and alertCross
    alert("Cross Short", alert.freq_once_per_bar_close)
    
    
    
//---------------------- Trend -------------------------
go_trend_long = false
go_trend_short = false 
var is_trend_long = false
var is_trend_short = false


if crossover(valEMA1[0], valEMA5[0]) and  valEMA5[0] < valEMA3[0]
    is_trend_long := true

if crossunder(valEMA1[0], valEMA5[0]) and is_trend_long
    is_trend_long := false
    
if crossover(valEMA1[0], valEMA3[0]) and  valEMA5[0] < valEMA3[0] and is_trend_long
    go_trend_long := true
    
    
if crossunder(valEMA1[0], valEMA5[0]) and  valEMA5[0] > valEMA3[0]
    is_trend_short := true

if crossover(valEMA1[0], valEMA5[0]) and is_trend_short
    is_trend_short := false
    
if crossunder(valEMA1[0], valEMA3[0]) and  valEMA5[0] > valEMA3[0] and is_trend_short
    go_trend_short := true

        
plotshape(go_trend_long,"Anti-crossing Long", style=shape.arrowup, location=location.belowbar, text="▲ AC", textcolor=#FFFFFF, color=#00FF0099)
if go_trend_long and alertTrend
    alert("Anti-crossing Long", alert.freq_once_per_bar_close)
    
plotshape(go_trend_short,"Anti-crossing Short", style=shape.arrowdown, location=location.abovebar, text="▼ AC", textcolor=#FFFFFF, color=#FF000099)
if go_trend_short and alertTrend
    alert("Anti-crossing Short", alert.freq_once_per_bar_close)



//-------------- Bud ----------------------
go_bud_long  = false 
var pclose   = 0.0
var popen    = 0.0
var phigh    = 0.0
var plow     = 0.0
var startUp      = 0
var onBudUp      = 0
var countBudUp   = 0

myLineBUD    = line.new(na, na, na, na, color=#FFFFFF, width=2, style=line.style_dotted)
labelBud     = label.new(na, na, style=label.style_none, textcolor=#FFFFFF, text="BUD ?")

//---- BUD UP ------
if (close > open and countBudUp == 0)
    pclose := close
    popen  := open
    phigh  := high
    plow   := low
    startUp:= bar_index
    onBudUp:= 1
    
if ((close < pclose and close > popen) or (high < phigh and low > plow)) and onBudUp == 1
    countBudUp := countBudUp + 1
    if countBudUp >= 2
        if startUp > 0
            myLineBUD = line.new(startUp, phigh, bar_index, phigh, color=#FFFFFF, width=2, style=line.style_dotted)
            line.delete(id=myLineBUD[1])
            //labelBud = label.new(bar_index - 1, phigh, style=label.style_none, textcolor=#FFFFFF, text="BUD ?")
            //label.delete(id=labelBud[1])
   
if close > phigh and countBudUp >= 2
    go_bud_long := true
    line.new(startUp, phigh, bar_index, phigh, color=#FFFFFF, width=2, style=line.style_dotted)
    label.new(bar_index-(countBudUp/2), phigh, style=label.style_none, textcolor=#FFFFFF, size=size.normal, text="▲ "+tostring(countBudUp))
    line.delete(id=myLineBUD[1])
    label.delete(id=labelBud[1])
    
if (high > phigh or low < plow or close > phigh or close < plow) and onBudUp == 1 
    countBudUp := 0
    onBudUp := 0
    
    if (close > open and countBudUp == 0)
        pclose := close
        popen  := open
        phigh  := high
        plow   := low
        startUp:= bar_index
        onBudUp:= 1

    
//---- BUD DOWN ------

var pcloseD   = 0.0
var popenD    = 0.0
var phighD    = 0.0
var plowD     = 0.0
var startDown    = 0
var onBudDown    = 0
var countBudDown = -1

myLineBUDDown = line.new(na, na, na, na, color=#FFFFFF, width=2, style=line.style_dotted)
labelBudDown  = label.new(na, na, style=label.style_none, textcolor=#FFFFFF, text="BUD ?")

if (close < open and countBudDown < 0)
    pcloseD := close
    popenD  := open
    phighD  := high
    plowD   := low
    startDown := bar_index
    onBudDown := 1
    countBudDown := 0
    
if (high < phighD and low > plowD) and onBudDown == 1
    countBudDown := countBudDown + 1
    if countBudDown >= 2 and startDown > 0
        myLineBUDDown = line.new(startDown, plowD, bar_index, plowD, color=#FFFFFF, width=2, style=line.style_dotted)
        line.delete(id=myLineBUDDown[1])
   
if close < plowD and countBudDown >= 2
    go_bud_long := true
    line.new(startDown, plowD, bar_index, plowD, color=#FFFFFF, width=2, style=line.style_dotted)
    label.new(bar_index-countBudDown, plowD, style=label.style_none, textcolor=#FFFFFF, size=size.normal, text="▼ "+tostring(countBudDown))
    line.delete(id=myLineBUDDown[1])
    label.delete(id=labelBudDown[1])
    
if (high > phighD or low < plowD or close > phighD or close < plowD) and onBudDown == 1 
    countBudDown := -1
    onBudDown := 0
    
    if (close < open and countBudDown == 0)
        pcloseD := close
        popenD  := open
        phighD  := high
        plowD   := low
        startDown := bar_index
        onBudDown := 1  

    
plotshape(go_bud_long,"BUD", style=shape.arrowup, location=location.abovebar, text="", color=#FFFFFF00)
if go_bud_long and alertBud
    alert("BUD", alert.freq_once_per_bar_close)



    