FARAZ.MATI20v
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © faryarfaraz67
//@version=4
study("FARAZ.MATI22v" , overlay=true)
src = input(close, title="Source")
len1 = input(5, minval=1, title="EMA1")
len2 = input(20, minval=1, title="SMA2")
len3 = input(50, minval=1, title="SMA3")
len4 = input(100, minval=1, title="SMA4")
len5 = input(200, minval=1, title="SMA5")
ma1 = ema(close, len1)
ma2 = sma(close, len2)
ma3 = sma(close, len3)
ma4 = sma(close, len4)
ma5 = sma(close, len5)
plot(ma1, title="EMA1", color=#ffeb3b,linewidth=1)
plot(ma2, title="SMA2", color=#060cfe,linewidth=1)
plot(ma3, title="SMA3", color=#f44336,linewidth=1)
plot(ma4, title="SMA4", color=#9598a1,linewidth=1)
plot(ma5, title="SMA5", color=#b2b5be,linewidth=3)

func_hma(style, length)=>

    return = wma((2 * wma(style, length / 2)) - wma(style, length), round(sqrt(length)))

shortPeriod = input(20, title="HMA")

shortHMA = func_hma(close, shortPeriod)
current = shortHMA[0]
prev = shortHMA[1]

plot(shortHMA, color=current > prev ? #368c3a : #770707, linewidth=3, title="HMA")

length = input(20, minval=1, title=" HMA")
hullma = wma(2*wma(src, length/2)-wma(src, length), floor(sqrt(length)))

length1 = input(20, minval=1,title="HMA")
hullma1 = wma(2*wma(src, length/2)-wma(src, length), floor(sqrt(length)))
plot(hullma1,color=#ffffff,style=plot.style_circles,linewidth=2,title="HMA")  


start = input(title="Start", type=input.float, step=0.001, defval=0.044)
increment = input(title="Increment", type=input.float, step=0.001, defval=0.02)
maximum = input(title="Maximum", type=input.float, step=0.01, defval=0.2)
psar = sar(start, increment, maximum)
col = psar < close ? 1 : -1
psarColor = col == 1 ? #81c784 : #e57373
psarPlot = plot(psar, title="Parabolic SAR", style=plot.style_stepline, linewidth=1, color=psarColor, transp=0)
conversionPeriods = input(9, minval=1, title="Conversion Line Length")
basePeriods = input(26, minval=1, title="Base Line Length")
laggingSpan2Periods = input(52, minval=1, title="Leading Span B Length")
displacement = input(26, minval=1, title="Displacement")
donchian(len) => avg(lowest(len), highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
p1 = plot(leadLine1, offset = displacement - 1, color=#114813,
	 title="Leading Span A")
p2 = plot(leadLine2, offset = displacement - 1, color=#3e1515,
	 title="Leading Span B")
fill(p1, p2, color = leadLine1 > leadLine2 ? color.rgb(67, 160, 71, 90) : color.rgb(244, 67, 54, 90))

RSI_Period = input(14, title='RSI Length')
SF = input(5, title='RSI Smoothing')
QQE = input(4.238, title='Fast E Factor')
ThreshHold = input(10, title="Thresh-hold")


Wilders_Period = RSI_Period * 2 - 1

Rsi = rsi(src, RSI_Period)
RsiMa = ema(Rsi, SF)
AtrRsi = abs(RsiMa[1] - RsiMa)
MaAtrRsi = ema(AtrRsi, Wilders_Period)
dar = ema(MaAtrRsi, Wilders_Period) * QQE

longband = 0.0
shortband = 0.0
trend = 0


// Alerts

e = input(true,  "Use Exponential MA"                               , group = "Elliott Wave Oscillator Settings")
d = input(7 ,    "Signal : Delay"         , minval=2, inline = "EWO", group = "Elliott Wave Oscillator Settings")
t = input(13,    "    Strength Threshold" , minval=1, inline = "EWO", group = "Elliott Wave Oscillator Settings")
h = input(false, "Display Histogram (on Linear Scale)"          , group = "Elliott Wave Oscillator Settings")

p = input(233,   "Plotting Length", group = "Display Settings")
source       = close 
ewo          = e ? (ema(source, 5)/ema(source, 34) - 1) * 100 : (sma(source, 5)/sma(source, 34) - 1) * 100
ewoSignal    = e ?  ema(ewo,d) : sma(ewo,d)
ewoHistogram = h and timeframe.isdwm ? e ? ema(source, 5) - ema(source, 34) : sma(source, 5) - sma(source, 34) : na

ewoColor = h and timeframe.isdwm ? ewoHistogram >=0 ? 
     (ewoHistogram[1] < ewoHistogram ? #006400   : color.green) : 
     (ewoHistogram[1] < ewoHistogram ? color.red : #910000) : na
plotshape(crossover (ewo, ewoSignal) and ewo < -t, title = "Strong Long" , color=#006400    , style=shape.arrowup  , location=location.belowbar, size=size.large , show_last = p) //, text="↑", textcolor=color.white)
plotshape(crossover (ewo, ewoSignal) and ewo > -t, title = "Long"        , color=#1b5e20    , style=shape.arrowup , location=location.belowbar, size=size.large  , show_last = p)
plotshape(crossunder(ewo, ewoSignal) and ewo >  t, title = "Strong Short", color=#910000    , style=shape.arrowdown , location=location.abovebar, size=size.large, show_last = p) //, text="↓", textcolor=color.white)
plotshape(crossunder(ewo, ewoSignal) and ewo <  t, title = "Short"       , color=color.red  , style=shape.arrowdown , location=location.abovebar, size=size.large ,show_last = p)

if h and not timeframe.isdwm
    if barstate.islast 
        label ewoLabel = label.new(bar_index, .97*low, text="warning ...", textcolor=color.white, textalign=text.align_left, style=label.style_label_up, tooltip="histogram plotting is supported for daily, weekly and monthly timeframe\nTo ged rid of this warning message disable hisrogram display") 
        label.delete(ewoLabel[1])

longAlertCondition  = crossover(ewo, ewoSignal)
alertcondition(longAlertCondition   , "Long : Early Warning"        , "EWO-S - Not Confirmed Probable Long Trade Opportunity\n{{exchange}}:{{ticker}}->\nPrice = {{close}},\nTime = {{time}}")
alertcondition(longAlertCondition[1], "Long : Trading Opportunity"  , "EWO-S - Probable Long Trade Opportunity\n{{exchange}}:{{ticker}}->\nPrice = {{close}},\nTime = {{time}}")

shortAlertCondition = crossunder(ewo, ewoSignal)
alertcondition(shortAlertCondition   , "Short : Early Warning"      , "EWO-S - Not Confirmed Probable Short Trade Opportunity\n{{exchange}}:{{ticker}}->\nPrice = {{close}},\nTime = {{time}}")
alertcondition(shortAlertCondition[1], "Short : Trading Opportunity", "EWO-S - Probable Short Trade Opportunity\n{{exchange}}:{{ticker}}->\nPrice = {{close}},\nTime = {{time}}")
