Asia Reversal Zone
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © NeverWishing

//@version=5
indicator(title="Asia Reversal Zone", shorttitle="ARZ", overlay=true)

// Get user input
timezone                = input.session(title="Timezone To Highlight", defval="2048-2128")
alertSessionStart       = input.bool(title="Alert When Session Starts?", defval=true)
alertWhenSessionStarts  = input.session(title="Alert When Session Starts At", defval="0830-0830")
alertSessionEnd         = input.bool(title="Alert When Session Ends?", defval=true)
alertWhenSessionEnds    = input.session(title="Alert When Session Ends At", defval="1830-1830")
paintBg                 = input.bool(title="Paint Background?", defval=true)
blankInsideCandles      = input.bool(title="Color Candles Within Zone?", defval=false)
hideOn240AndAbove       = input.bool(title="Hide on 4HR And Above?", defval=false)
hideTimeframeCB         = input.bool(title="Hide On Other Timeframe?", defval=false)
hideTimeframe           = input.string(title="Other Timeframe To Hide", defval="60")

// Determine whether or not this timeframe is to be ignored
hide = hideTimeframeCB and timeframe.period == hideTimeframe or 
   hideOn240AndAbove and 
   (timeframe.period == "240" or 
   timeframe.period == "D" or 
   timeframe.period == "W" or 
   timeframe.period == "M")

// InSession() determines if a price bar falls inside the specified session
InSession(sess) => na(time(timeframe.period, sess + ":1234567")) == false

// Color the background of each relevant session and/or bar
bgcolor(color=InSession(timezone) and paintBg and not hide ? color.new(color.red, 75) : na, title="Not In Session")
barcolor(color=InSession(timezone) and blankInsideCandles and not hide ? color.white : na)

// Send out an alert if this candle meets our conditions
alertcondition((InSession(alertWhenSessionStarts) and alertSessionStart) or (InSession(alertWhenSessionEnds) and alertSessionEnd), title="Session Alert!", message="Session signal for {{ticker}}")

plot(close)
