Wicked signals
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mildSnail31034

//@version=5
indicator("Wicked signals")


len = input.int(title="Lookback for wicks",defval=6)
lenc = 0
volf = input.bool(title="Volume filter",defval=true)
lenvolma = input.int(title="Volume MA",defval=20)
volma = ta.ema(volume,lenvolma)
usehtf = input.bool(title="Use Higher Timeframe",defval=true)
//timeframe helper
f_chartTfInMinutes() => 
    float _return = timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)
  

tf = f_chartTfInMinutes()
shtf()=>
    if timeframe.isintraday
        htf = tf
        if usehtf and tf<5
            htf:=5
        if usehtf and tf==5
            htf:=15
        if usehtf and tf>15 and tf<60
            htf:=60
        if usehtf and tf>60 and tf<240
            htf:=240
        if usehtf and tf>=240 and tf<1440
            htf:=1440
        
        str.tostring(htf)
    else
        timeframe.period

phiex = ta.pivothigh(len,lenc)
ploex = ta.pivotlow(len,lenc)



phi = request.security(syminfo.tickerid,shtf(),phiex)
plo = request.security(syminfo.tickerid,shtf(),ploex)
htfclose = request.security(syminfo.tickerid,shtf(),close)



volcond = volume>volma?true:false
volfilter=volf?volcond:true

wickup=open>close?high-open:high-close
wickdown=open<close?open-low:close-low
wicks = wickup>wickdown?wickup:wickdown
wicksma=ta.rma(wicks,55)
top = phi and phi>phi[1] and wicks>wicksma and volfilter
bottom = plo and plo<plo[1] and wicks>wicksma and volfilter

bgcolor(top?color.red:na)
bgcolor(bottom?color.green:na)

// Getting inputs
RSI = input.int(title="RSI length",defval=3, minval=1)
out = ta.rsi(close,RSI)

fast_length = input(title="Fast Length", defval=3)
slow_length = input(title="Slow Length", defval=6)
src = out
signal_length = input.int(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 5)
sma_source = input.string(title="Oscillator MA Type",  defval="EMA", options=["RMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["RMA", "EMA"])
// Plot colors
col_macd = input(#2962FF, "MACD Line  ", group="Color Settings", inline="MACD")
col_signal = input(#FF6D00, "Signal Line  ", group="Color Settings", inline="Signal")
col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
// Calculating
fast_ma = sma_source == "RMA" ? ta.rma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "RMA" ? ta.rma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
plot(macd, title="MACD", color=col_macd)
plot(signal, title="Signal", color=col_signal)






