Untitled

 avatar
unknown
plain_text
2 years ago
2.7 kB
1
Indexable
//@version=4
study("Session Breakout, Candle Patterns, and Previous Day Levels", overlay=true)

// Define session start and end times
asianStart = input("00:00:00", title="Asian Session Start")
asianEnd = input("03:00:00", title="Asian Session End")

londonStart = input("03:00:00", title="London Session Start")
londonEnd = input("06:00:00", title="London Session End")

nyStart = input("06:00:00", title="New York Session Start")
nyEnd = input("09:00:00", title="New York Session End")

// Calculate session boundaries
isAsianSession = time >= timestamp(year, month, dayofmonth, hourminsec(asianStart)) and time < timestamp(year, month, dayofmonth, hourminsec(asianEnd))
isLondonSession = time >= timestamp(year, month, dayofmonth, hourminsec(londonStart)) and time < timestamp(year, month, dayofmonth, hourminsec(londonEnd))
isNySession = time >= timestamp(year, month, dayofmonth, hourminsec(nyStart)) and time < timestamp(year, month, dayofmonth, hourminsec(nyEnd))

// Calculate session breakout conditions
asianResistance = high[1]
londonResistance = high[1]
nyResistance = high[1]

asianBreakout = high > asianResistance and high[1] <= asianResistance
londonBreakout = high > londonResistance and high[1] <= londonResistance
nyBreakout = high > nyResistance and high[1] <= nyResistance

// Calculate candle patterns
isMCandle = close < open and low <= low[1] and low <= low[2] and high >= high[1] and high >= high[2]
isWCandle = close > open and high >= high[1] and high >= high[2] and low <= low[1] and low <= low[2]

// Calculate previous day's resistance and support levels
prevHigh = request.security(syminfo.tickerid, "D", high[1])
prevLow = request.security(syminfo.tickerid, "D", low[1])

// Calculate breakouts of previous day's levels
highBreakout = high > prevHigh
lowBreakout = low < prevLow

// Create alarms for session breakouts and candle patterns
alertcondition(asianBreakout and isMCandle, title="Asian Session M Candle Breakout")
alertcondition(asianBreakout and isWCandle, title="Asian Session W Candle Breakout")

alertcondition(londonBreakout and isMCandle, title="London Session M Candle Breakout")
alertcondition(londonBreakout and isWCandle, title="London Session W Candle Breakout")

alertcondition(nyBreakout and isMCandle, title="New York Session M Candle Breakout")
alertcondition(nyBreakout and isWCandle, title="New York Session W Candle Breakout")

// Create alarms for breakouts of previous day's levels
alertcondition(highBreakout and isMCandle, title="High Breakout and M Candle Formation")
alertcondition(lowBreakout and isWCandle, title="Low Breakout and W Candle Formation")

// Plot session boundaries
bgcolor(isAsianSession ? color.yellow : na, title="
Editor is loading...