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

//@version=5
//Indicator by STH_Seththeesin_Thakanok - Published

//Test Indicator - This script/indicator is designed with the main purpose of identifying the strength of the instrument. 
//Description added at each methods. Inputs can be changed by users as per their own rules as per their matching style. 

indicator(title='Seth_Signal', shorttitle='STH_Signal', overlay=true)

//PSAR - Default PSAR setting with the marking of red and green as per position of above or below candle

pSARbeginningValue = input.int(2, minval=0, maxval=10, title='PSAR Beginning Value')
pSARendValue = input.int(2, minval=1, maxval=10, title='PSAR End Value')
pSARmultiplierValue = input.int(2, minval=0, maxval=10, title=' PSAR Multiplier Value')

pSARbeginningMethod = pSARbeginningValue * .01
pSARendMethod = pSARendValue * .10
pSARmultiplierMethod = pSARmultiplierValue * .01

pSAR_UpValue = ta.sar(pSARbeginningMethod, pSARmultiplierMethod, pSARendMethod)
pSAR_DownValue = ta.sar(pSARbeginningMethod, pSARmultiplierMethod, pSARendMethod)

pSAR_UpColor = close >= pSAR_DownValue ? color.green : na
pSAR_DownColor = close <= pSAR_UpValue ? color.red : na

plot(pSAR_UpValue ? pSAR_UpValue : na, style=plot.style_circles, color=pSAR_UpColor, linewidth=1, title='Upside PSAR')
plot(pSAR_DownValue ? pSAR_DownValue : na, style=plot.style_circles, color=pSAR_DownColor, linewidth=1, title='Downside PSAR')

//Zone Identification - This is once again ATR based method to identify the zone based on its strength

zoneSource = input(hl2, title='Source')
zoneLength = input(defval=8, title='ATR Zone Length')
zoneMultiplier = input.float(defval=3.3, step=0.1, title='ATR Zone Multiplier')
zoneATR = ta.atr(zoneLength)

downZone = zoneSource + zoneMultiplier * zoneATR
downZoneNew = nz(downZone[1], downZone)
downZone := close[1] < downZoneNew ? math.min(downZone, downZoneNew) : downZone
upZone = zoneSource - zoneMultiplier * zoneATR
upZoneNew = nz(upZone[1], upZone)
upZone := close[1] > upZoneNew ? math.max(upZone, upZoneNew) : upZone

zoneDecider = 1
zoneDecider := nz(zoneDecider[1], zoneDecider)
zoneDecider := zoneDecider == -1 and close > downZoneNew ? 1 : zoneDecider == 1 and close < upZoneNew ? -1 : zoneDecider

redZone = zoneDecider == -1 and zoneDecider[1] == 1
greenZone = zoneDecider == 1 and zoneDecider[1] == -1
downZoneColor = zoneDecider == -1 ? color.red : color.gray
upZoneColor = zoneDecider == 1 ? color.green : color.gray

downZonePlot = plot(zoneDecider == 1 ? na : downZone, style=plot.style_linebr, linewidth=2, color=color.new(color.red, 0), title='Sell')

plotshape(redZone ? downZone : na, location=location.absolute, style=shape.diamond, size=size.tiny, color=color.new(color.red, 0), title='Sell')
plotshape(redZone ? downZone : na, location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), title='Sell', text='Sell')

upZonePlot = plot(zoneDecider == 1 ? upZone : na, style=plot.style_linebr, linewidth=2, color=color.new(color.green, 0), title='Buy')

plotshape(greenZone ? upZone : na, location=location.absolute, style=shape.diamond, size=size.tiny, color=color.new(color.green, 0), title='Buy')
plotshape(greenZone ? upZone : na, location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), title='Buy', text='Buy')

neutralZonePlot = plot(ohlc4, style=plot.style_circles, linewidth=0, title='Zone Style')
fill(neutralZonePlot, downZonePlot, color=downZoneColor, title='Down Zone Color', transp=90)
fill(neutralZonePlot, upZonePlot, color=upZoneColor, title='Up Zone Color', transp=90)

//1 EMA - Short Term

emaLowerPeriod = input.int(9, minval=1, title='EMA Lower Period')

emaLower = ta.ema(input(close), emaLowerPeriod)

plot(emaLower, color=color.new(color.fuchsia, 0), linewidth=2, title='EMA Lower Period')

//2 EMA - Medium Term - Optional
showEMA2 = input(false, title='EMA - Medium Term')

emaMediumPeriod = input.int(27, minval=1, title='EMA Medium Period')

emaMedium = ta.ema(input(close), emaMediumPeriod)

plot(showEMA2 and emaMedium ? emaMedium : na, color=color.new(color.aqua, 0), linewidth=2, title='EMA Medium Period')

//1 HMA - Long Term

hmaLongPeriod = input.int(200, minval=1, title='HMA Long Period')

hmaLong = ta.hma(input(close), hmaLongPeriod)

plot(hmaLong, color=color.new(color.gray, 0), linewidth=2, title='HMA Long Period')

//Bar Color
isCloseAbove = close > emaLower and close > hmaLong
isCloseBelow = close < emaLower and close < hmaLong
isCloseBetween = close > emaLower and close < hmaLong or close < emaLower and close > hmaLong
//isBullish      = (close > upZone)
//isBearish      = (close < downZone)

isNeutral = close > pSAR_DownValue and isCloseBelow or close < pSAR_DownValue and isCloseAbove

//barcolor((isNeutral or isCloseBetween) ? color.yellow: (isCloseBelow and isBearish) ? color.red: (isCloseBelow and isBullish) ? color.orange:  (isCloseAbove and isBearish) ? color.lime: (isCloseAbove and isBullish) ? color.green : color.black )

barcolor(isNeutral or isCloseBetween ? color.yellow : isCloseBelow ? color.red : isCloseAbove ? color.green : color.black)


//Disclaimer: Idea of publishing this script is to identify the strength of the instrument using multiple confirmation. 
//Disclaimer: Using this indicator, changing inputs, and trading decisions are upto the users/traders.

