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)
- // Source we will be averaging.
- source = volume
- // Defines 15 min window Murat is interested in.
- timeSession = time(timeframe.period, "1430-1445")
- // Condition on which we want to calculate our average.
- condition = false
- // // The following taken from: https://stackoverflow.com/questions/58063534/find-high-low-for-a-particular-intraday-time-interval
- // locVol = 0.0
- // // Gets the high/low from the 1min resolution.
- // sessionVolume = security(syminfo.tickerid, "15", volume, lookahead=true)
- // // The hour info below should line up with this info. time_session1 = time(timeframe.period, "1700-1701")
- if hour == 14 and minute == 30
- condition := true
- // locVol := sessionVolume
- // else
- // locVol := locVol[1]
- // Condition on which we want to calculate our average.
- // condition = change(timeSession) and timeSession==1
- // if change(timeSession) and timeSession==1
- // condition := 1
- // ————— Case 2. The average of "source" for the last "x" occurrences where "condition" is true.
- x = input(3, "Case 2: Average this many last occurrences")
- 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 _cnt*2880
- _loopLimit = _cnt * 1666
- 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), "Case 2 Average", color.fuchsia)
- // Plots and Debug Plots
- // plot (locVol, title="Session Volume", color=color.aqua, style=plot.style_linebr)
- plot(condition==true?1:0, title= "Condition", transp=100)
- plot(na(timeSession) ? 0 : 1, title="timeSession", transp=100)
- // plot(locVol, title="locVol", transp=100)
- //END//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement