OPEN-SOURCE SCRIPT

Relative Volume (rVol), Better Volume, Average Volume Comparison

Zaktualizowano
This is the best version of relative volume you can find a claim which is based on the logical soundness of its calculation.
I have amalgamated various volume analysis into one synergistic script. I wasn't going to opensource it. But, as one of the lucky few winners of TradingClue 2. I felt obligated to give something back to the community.

Relative volume traditionally compares current volume to prior bar volume or SMA of volume. This has drawbacks. The question of relative volume is "Volume relative to what?" In the traditional scripts you'll find it displays current volume relative to the last number of bars. But, is that the best way to compare volume. On a daily chart, possibly. On a daily chart this can work because your units of time are uniform. Each day represents a full cycle of volume. However, on an intraday chart? Not so much.

Example: If you have a lookback of 9 on an hourly chart in a 24 hour market, you are then comparing the average volume from Midnight - 9 AM to the 9 AM volume. What do you think you'll find? Well at 9:30 when NY exchanges open the volume should be consistently and predictably higher. But though rVol is high relative to the lookback period, its actually just average or maybe even below average compared to prior NY session opens. But prior NY session opens are not included in the lookback and thus ignored.

This problem is the most visibly noticed when looking at the volume on a CME futures chart or some equivalent. In a 24 hour market, such as crypto, there are website's like skew can show you the volume disparity from time of day. This led me to believe that the traditional rVol calculation was insufficient. A better way to calculate it would be to compare the 9:30 am 30m bar today to the last week's worth of 9:30 am 30m bars. Then I could know whether today's volume at 9:30 am today is high or low based on prior 9:30 am bars. This seems to be a superior method on an intraday basis and is clearly superior in markets with irregular volume

This led me to other problems, such as markets that are open for less than 24 hours and holiday hours on traditional market exchanges. How can I know that the script is accurately looking at the correct prior relevant bars. I've created and/or adapted solutions to all those problems and these calculations and code snippets thus have value that extend beyond this rVol script for other pinecoders.

The Script
This rVol script looks back at the bars of the same time period on the viewing timeframe. So, as we said, the last [x] 9:30 bars. Averages those, then divides the: [Current Volume / Average Volume]. The result is a percentage expressed as x.xxx. Thus 1.0 mean current volume is equal to average volume. Below 1.0 is below the average and above 1.0 is above the average.

This information can be viewed on its own. But there are more levels of analysis added to it.
  • Above the bars are signals that correlate to the "Better Volume Indicator" developed by, I believe, the folks at emini-watch and originally adapted to pinescript by LazyBear. The interpretation of these symbols are in a table on the right of the indicator.
  • The volume bars can also be colored. The color is defined by the relationship between the average of the rVol outputs and the current volume. The "Average rVol" so to speak. The color coding is also defined by a legend in the table on the right.


These can be researched by you to determine how to best interpret these signals. I originally got these ideas and solid details on how to use the analysis from a fellow out there, PlanTheTrade.

I hope you find some value in the code and in the information that the indicator presents. And I'd like to thank the TradingView team for producing the most innovative and user friendly charting package on the market.
(p.s. Better Volume is provides better information with a longer lookback value than the default imo)

Credit for certain code sections and ideas is due to:
LazyBear - Better Volume
Grimmolf (From GitHub) - Logic for Loop rVol
R4Rocket - The idea for my rVol 1 calculation
And I can't find the guy who had the idea for the multiples of volume to the average. Tag him if you know him

Final Note: I'd like to leave a couple of clues of my own for fellow seekers of trading infamy.
Indicators: indicators are like anemometers (The things that measure windspeed). People talk bad about them all the time because they're "lagging." Well, you can't tell what the windspeed is unless the wind is blowing. anemometers are lagging indicators of wind. But forecasters still rely on them. You would use an indicator, which I would define as a instrument of measure, to tell you the windspeed of the markets. Conversely, when people talk positively about indicators they say "This one is great and this one is terrible." This is like a farmer saying "Shovels are great, but rakes are horrible." There are certain tools that have certain functions and every good tool has a purpose for a specific job. So the next time someone shares their opinion with you about indicators. Just smile and nod, realizing one day they'll learn... hopefully before they go broke.

How to forecast: Prediction is accomplished by analyzing the behavior of instruments of measure to aggregate data (using your anemometer). The data is then assembled into a predictive model based on the measurements observed (a trading system). That predictive model is tested against reality for it's veracity (backtesting). If the model is predictive, you can optimize your decision making by creating parameter sets around the prediction that are synergistic with the implications of the prediction (risk, stop loss, target, scaling, pyramiding etc).

<3
Informacje o Wersji
Minor Adjustments based on analysis of source script written in EasyLanguage. The impact is minimal, but I recommend using the latest version
Informacje o Wersji
Update Notes
  • Update to v5.
  • In this edition I completely overhauled Better-er Volume calculations to be consistent with the concepts that the indicator is based on. Most importantly, the update involves how the volume is weighted. The conditions to test for an event have also been simplified.
  • You can now view Total Volume as well instead of relative volume.
  • You can plot the weighted volume to see how the volume is being weighted and used in the Better-er Volume and Volume Ratings calculations
  • Resolved color issue. The purple plotchar() was blended in to the purple column color. Clarified the plotchar() to improve visibility.
  • There's also a fun code snippet in here. A ratings system. It is a pair of arrays. One that collects data points and a copy of that array that sorts data points. Then, using plotchar() determines which rating is merited based on the data point's position in the array. I think it could be useful for everyone. In this case we are looking for a basic fractal of the readout of Weighted Volume. So look 2 bars left and right, determine the pivot, and store the value. When a new "highest pivot" signal comes. Empty the array and add the new high. Its a neat bit of logic.


New Better-er Volume Calculation
Regardless of whether the bar closes green or red, the volume in each candle is to some extent bullish and some extent bearish. The question (in the absence of true tick data) is how to weight a candle's volume.

The original Better Volume indicator is predicated on these same concepts, but in my research was too fancy about it. I wanted to drill down to the very basics of what I was looking for.

Bull volume is quantified as the volume weighted by the percentage of the candle measured: [(close - low) / (high - low)]. The volume executed from the low of the bar to the close of the bar represents the volume executed to push the candle off the low. The bar could close bearish, but have a very long wick, implying the bulls pushed it hard off the low and closed high relative to the range. Thus you could have a bullish candle with a bearish close.

Bear volume is quantified as the volume weighted by the percentage of the candle measured: [(high - close) / (high - low)]. From the high, down to the close is the distance the bears pushed the price down in the candle. The bar could close bullish, but with a long upper wick. This could imply that sufficient bearish volume was present to push price down.

Issues.
1. Just because there is a long wick does not mean that there was a push, it could mean that (in the case of a long bottom wick) that the bears pushed it down with little effort and backed down so as not to push price against themselves, meaning the only thing holding price up is the bid liquidity being offered by the market makers and very low timeframe scalping algos, which operate with small volume requirements.
2. The underlying assumption of this method is that both sides are PUSHING against each other. This assumption is that bulls want higher prices bears want lower prices. This is not always true. Sometimes the bulls pull price lower by lowering their bids and bears pull by raising their asks. But without true tick data, you can only assume one or the other.
Maybe at some point a PULL model can be developed under the opposite assumption. For now, the signals coincide more strongly with signals expected from the Better Volume thesis which is: for volume climaxes, range acts as a volume multiplier and for churn volume, range acts as a volume dividend.

Ratings System
I created a ratings system for spikes in bull and bear volume. When a Better-er Volume signal triggers, the array of stored pivots is reset to zero and value of weighted volume for the new signal is stored at index 0 and shows a rating of 1 (highest). Each subsequent found spike of the weighted volume is then rated against the last better-er volume signal value and is tracked 1-5. In instances of many spikes, a spike can be rated 1 but not coincide with a better-er volume signal because the last signal has fallen out of the array (max 5).
Churn bar ratings are at the bottom because they can overlap with Climax Volume Up and Climax Volume Down.

Important to note. This indicator is not designed at all to use all these signals at once. This indicator can be parsed apart in many different ways to create useful signals. Right now I'm working on combining the signals provided with price action signals, wherein, I won't be seeing any of these calculations on the chart as it will be running in an overlaid strategy. Be creative with how you use it.

I'm open to hearing about better-er ways of measuring volume. Lookup "Better Volume emini" and you'll find an article that provides further information on how the better volume concept functions if you're interested

To utilize original Better Volume calculations, use v12 of the indicator.
Informacje o Wersji
Drastically Faster | No more lookback limitations | Higher degree of accuracy on irregular sessions | Fixed bar colors | Increased portability | Simplified Validation.
Thanks to the introduction of Matrices, we don't need to loop back through bars to find the volume values required for calculation, we just store them as we go.
Also, when we want to validate the data, we can just show the matrix using my Array / Matrix HUD (see profile for library).

Instructions for setup:
Do not forget to set the length of the day for the market that you're trading. Default is set up for the CME S&P Futures market. So, session length is 23 hours as it is closed for 1 hr between 16:00 and 17:00.
Do not forget to set the ending time based on the chart. CME markets open at 18:00 and that is when the time resets and the next day's volume information will start being put into the next column.
You will get inaccurate outputs if these are not correctly set.

Note: I haven't tested this on the seconds timeframes. I imagine you might be off a bit because I didn't include seconds as a part of the reset parameters, but its probably not by much at all. Also, because of the limited history on seconds intervals, you won't get much out of the indicator anyway. However, if this negatively affects anyone's experience, please comment below and I'll address it.
Informacje o Wersji
Some request for the legend table to be available. It is now available using switch in the settings menu
Informacje o Wersji
Fixed bug wherein certain timeframes caused a non-integer barsInSession value.

Thanks to kunjmech2004 and ahmeisa8988 for pointing it out.
Let me know what else you find.
When in doubt, turn on the Validation Table and check the volume bars against the displayed array. Till next bug friends.
Informacje o Wersji
Thank you for all your help in making this better.
I have successfully tested it on Indian Market tickers (What a weird market), dwm timeframes, and odd timeframes (like 3h)

Seems the bugs have largely related to odd events, such as a prolonged market and/or emergency shutdowns after disasters and other such odd events. That and there was a problem where if the timeframe chosen did not cause the bars to end on the same time interval as the market open, you would get an error. But I think adding the condition `or time("D") != time("D")[1]` has resolved those issues. Instead of a 1 for non-intraday charts I swapped it for `timeframe.multiplier` Hopefully that takes care of everything.
Informacje o Wersji
rVol v3. New Method. New Features.

I've been problem solving and found a new method to determine the proper intervals. You no longer need to enter the session length. However, you do need to know whether the ticker you're looking at makes an adjustment for Daylight Savings Time. Hilarious. But that is something there is no easy way to make known to the script so the user has to tell it.
This will work on just about everything I've tried it on. Indian stock market tickers, FOREX, Crypto, Futures. I've resolved the issue of irregular session lengths and session timing. So, really it should just work like we want it to.

If you want to test the accuracy of the script. Use the Validation Table check box to see what volume values are being evaluated. Also, a new feature is you can view historical states of arrays, so you can check not just the live bar, but the prior bars.
You will notice if you do that, there is an additional data point on the live bar. This is because a value has to be removed from the historical bars. It was including the completed bar that was the numerator in the equation, thus distorting the historical view. I resolved this, but as a byproduct, the current bar has an additional data point. But based on my observation this tends to barely have any affect on the live bar but does distort all the historical bars, so I left it that way.

Use on Seconds and D/W/M intervals.
You don't get a lot of chart history when using the seconds intervals. You really can't apply the same logic with that limitation. At the same time, if you're looking at a seconds interval, I figure you're most interested in what's going to be happening in the next couple minutes, thus making the context of the most recent minutes more valuable than things that happened thousands of bars ago. So, on the seconds interval the volume is going to be calculated the same way it is on the Daily, Weekly, and Monthly intervals. It will calculate the volume sequentially in the past rather than matching timestamps like it does on intraday bars. So 60 cycles on a (9:35AM) 5m bar will show you the Volume on this bar Relative to the last 60 (9:35AM) 5m bars, but on the 30 seconds interval (or the daily interval) you will be looking at the volume of this bar relative to the last 30 minutes (60 - 30 second bars) or 60 days (in the case of the daily chart). In testing the seconds intervals do seem to show momentum characteristics in the volume by doing it this way, which is something you're looking for trading on mega-ltfs.

New Features:
You will find that there are many unique ways to analyze volume information that can yield helpful data to consider in your trading. This of course already had rVol, Better-er volume, and bar coloring to match average thresholds.
I'm now introducing Volume Per Tick and the Z-Score of Log(volume).

Volume Per Tick = Volume / Ticks in range (high - low). This distributes the volume evenly between each tick and thus approximates about how much volume was required to move the price 1 tick. Its not dead accurate its on average. in cases of long wicks for example volume had to push it down, then push it back up. I've worked with this for a long time and the best results come from keeping it simple and just taking the volume / range and getting the general idea of how much volume was required to move price in that price range.

Z-Score of Log(volume) = (logVolume - avgLogVolume) / stdevLogVolume. Log volume in some ways normalizes the output while also making it a vector. The sample size chosen is 1000. Its a bit arbitrary, but that is a large enough sample to get a good idea of the mean and standard deviation. Then the log(volume) of the current bar is compared to it to generate a z-score. The coloring is different on these bars because what's important is the volume above or below the zero line AND was the candle a bull or bear bar. You'll see that in bear trends like we have now, you'll have red positive z-scores to be dominant. Also, when a very large z-score manifests, you'll notice that candle most often presents a very strong s/r level and if that level gets broken, then breakout is normally good for at least a scalp.

Volume trading is fantastic because "big money, makes money" most of the time (or they would be out of business) and they can hide, but they have a very being invisible. Also, you can see market consensus. It doesn't necessarily plainly give us a forecast, that's at your discretion to make your guess, but it reliably tells us exactly what everyone is doing right now. If you spend time with this indicator and really think through the implications of its calculations, I believe you will do very well with it.

I hope its useful to you. Trade well. (same as before. Let me know what bugs you come up with, but I think this method is going to be easy to work with)
averagevolumebettervolumerelativerelativevolumervolVolume IndicatorvolumeanalysisVolume

Skrypt open-source

W prawdziwym duchu TradingView autor tego skryptu opublikował go jako open source, aby inwestorzy mogli go zrozumieć i zweryfikować. Pozdrowienia dla autora! Możesz go używać bezpłatnie, ale ponowne użycie tego kodu w publikacji podlega Zasadom Regulaminu. Możesz go oznaczyć jako ulubione, aby użyć go na wykresie.

Chcesz użyć tego skryptu na wykresie?


Również na:

Wyłączenie odpowiedzialności