Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LOVE JOY PEACE PATIENCE KINDNESS GOODNESS FAITHFULNESS GENTLENESS SELF-CONTROL
- // © JoshuaMcGowan
- //@version=4
- // Murat Notes: Calculate the volume from the core trading session opening 9.30-9.45 EST of the last 30 days. Build an average. This is the relative volume= RVol
- // Than look for the volume opening of the day. If it is 20% above the the Rvol it is a trending market. Means support and resistance levels rarely will hold. a break out or flush through resistance levels are quite probable.
- // in a range of +20%- -20% it is a normal trading day.
- // If opening volume is under 20% than it will probably be a ranging market (inside day, so inside last days volume area.)
- // Original Code: https://www.tradingview.com/script/isSfahiX-Averages-PineCoders-FAQ/
- // @author=LucF, for PineCoders
- study("Thirteen Friends - Relative Volume", overlay=false, max_bars_back=5000)
- // Source we will be averaging. Testing using vol_sess1 as source to get around bar lookback limitation.
- source = volume
- // Will be adding in Inputs for New York, London, and Tokyo
- // London - Opening Hours 8:00am (UTC 800)
- // New York - Opening Hours 9:30am (UTC 1430)
- // Tokyo - Opening Hours 9:00am (UTC 0000)
- sessionType = input(title="Session Selection", options=["New York", "London", "Tokyo"], defval="New York")
- session = sessionType == "New York" ? time(timeframe.period, "1430-1445") :
- sessionType == "London" ? time(timeframe.period, "0800-0815") :
- sessionType == "Tokyo" ? time(timeframe.period, "0000-0015") :
- na
- // Defines 15 min window Murat is interested in. // Commented out when adding session selection inputs.
- // timeSession = time(timeframe.period, "1430-1445")
- // Condition on which we want to calculate our average.
- condition = false
- // The hour info below should line up with this info. time_session1 = time(timeframe.period, "1430-1445")
- // The following taken from: https://stackoverflow.com/questions/58063534/find-high-low-for-a-particular-intraday-time-interval
- if (hour == 14 and minute == 30) and (sessionType=="New York")
- condition := true
- if (hour == 08 and minute == 00) and (sessionType=="London")
- condition := true
- if (hour == 00 and minute == 00) and (sessionType=="Tokyo")
- condition := true
- // ————— Case 2. The average of "source" for the last "x" occurrences where "condition" is true.
- x = input(30, "Opening Sessions")
- avgWhenLast(_src, _cond, _cnt) =>
- // Returns average of _src for the last _cnt occurrences of _cond (lookback length = _cnt*10).
- _total = 0.0
- _count = 0
- // Since we don't know how many bars we must go back to find the x occurrences we need,
- // we use _cnt*10 as the lookback upper bound, hoping we can find what we need in those bars.
- // This will generate a runtime error if _cnt is too high.
- // On the 15min chart the conditon occurs every 96 bars. If using 30 conditions as average would need 2880
- // _loopLimit = _cnt * 1666 // commenting out this original line since we do know how many bars back we need
- _loopLimit = 2881
- for _i = 0 to _loopLimit
- if _cond[_i]
- // We found an occurrence, increment count and add source to total.
- _count := _count + 1
- _total := _total + _src[_i]
- if _count == _cnt
- // We've reached our count, exit loop.
- break
- // Calculate average. If we haven't found the required number of occurrences, set to na.
- _average = _count == _cnt ? _total / _cnt : na
- plot(avgWhenLast(source, condition, x), "Relative Volume", color.fuchsia)
- // Now that we have the relative volume we can setup the +- 20% levels to monitor
- limit = (avgWhenLast(source, condition, x)) * 0.2
- upper = (avgWhenLast(source, condition, x)) + limit
- lower = (avgWhenLast(source, condition, x)) - limit
- // Adding in TV Vol Study
- barColorsOnPrevClose = input(title="Color bars based on previous close", type=input.bool, defval=false)
- palette = barColorsOnPrevClose ? close[1] > close ? color.red : color.green : open > close ? color.red : color.green
- plot(volume, color = palette, style=plot.style_columns, title="Volume", transp=65)
- // Additional Plots and Debug Plots
- plot (upper, title="upper", color=color.aqua, style=plot.style_linebr, linewidth=2)
- plot (lower, title="lower", color=color.aqua, style=plot.style_linebr, linewidth=2)
- // plot(condition==true?1:0, title= "Condition", transp=100)
- // plot(na(timeSession) ? 0 : 1, title="timeSession", transp=100)
- // plot((volume[1] > upper[1]) and (condition[1]==true) ? 1 : 0, title="Trending Alert", transp=100)
- // plot((volume[1] < lower[1]) and (condition[1]==true) ? 1 : 0, title="Ranging Alert", transp=100)
- // Labels
- showLabels = input(true, "Show Labels")
- trend = (volume[1] > upper[1]) and (condition[1]==true)
- range = (volume[1] < lower[1]) and (condition[1]==true)
- plotshape(showLabels==true and trend ? upper : na, title="Trending Label", color=color.aqua, text="Hunt\nTrending Setups",
- textcolor=color.white,
- style=shape.labeldown,
- location=location.absolute)
- plotshape(showLabels==true and range ? lower : na, title="Ranging Label", color=color.aqua, text="Hunt\nRanging Setups",
- textcolor=color.white,
- style=shape.labelup,
- location=location.absolute)
- // Alert Conditions
- // Need to test these out fully but first crack at it. Might need timeSession[1]==1 and volume[1] for intended effect.
- alertcondition((volume[1] > upper[1]) and (condition[1]==true), title="Trending Market", message="Trending Market")
- alertcondition((volume[1] < lower[1]) and (condition[1]==true), title="Ranging Market", message="Ranging Market")
- //PMAFTW//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement