OPEN-SOURCE SCRIPT

Delta Volume Columns [LucF]

アップデート済
Displays delta volume columns using intrabar volume information. Each volume column is divided into three sections: buying, selling and neutral volume. Volume for each section is determined from the volume and price movement of each intrabar at a user-selected lower resolution.

Features include:
- Choice of color themes for either dark or light chart backgrounds
- Delta volume columns
- Volume Balance displayed as the difference between the MAs of buying and selling volume
- Display of divergences between a bar’s volume balance and the bar’s price movement (example: buying volume > selling volume but close < open). Divergences can be shown in 2 different color schemes (including green/red showing a tentative direction), on volume columns and/or on chart bars
- Display of bar by bar volume balance with highlighting of above average volume
- Display of the usual total volume MA
- Choice of the lower resolution used to retrieve intrabar information
- Alerts configurable on any combination of the markers, with control over long/short direction
- Choice of 3 different markers:
1. Double bumps: two consecutive bars where buying or selling volume is in the same direction and where volume > volume MA
2. Divergence confirmations: direction of the price bar following a price/volume balance divergence
3. Volume balance shifts: zero level crossings of the volume balance MA delta

The chart shows the two main modes of display:
- Top pane: shows the stacked volume columns with divergences in orange and the flattened volume balance MAs delta at the bottom of the volume columns. This volume balance is the same shown in the bottom pane. The top pane also shows the instant volume balance strip above the volume columns. The strip’s colors show which of the buying or selling volume was greater, and colors are brighter if the total volume was above the total volume MA.
- Bottom pane: shows the volume balance MAs delta with markers 1 and 2. Given that this graphic has no price momentum component, I find quite eerie how it often looks like a momentum-based signal.
The default 5 minute intrabar resolution is used in combination with the weekly chart, which is excessive.


This script uses a special characteristic of the security() function’s behavior when it is sent to a resolution lower than the chart’s resolution. Details are given in the script’s comments. This method has the advantage of working under more circumstances than some of the other loop-based methods, but it also has its limits.


IMPORTANT
This is what you need to know:
- The method used does not work on the realtime bar—only on historical bars. Consequently, the volume column shown on the realtime bar is a normal volume column plotted in green or red, following price movement. The column will only show delta volume information after it closes and becomes a historical bar.
- The indicator only works on some chart resolutions: 5, 10, 15 and 30 minutes, 1, 2, 4, 6, and 12 hours, 1 day, 1 week and 1 month. The script’s code can be modified to run on other resolutions, but chart resolutions must be divisible by the lower resolution used for intrabars.
- Intrabar resolutions can be selected from 1, 5, 15, 30, 45 minutes, 1, 2, 3, 4 hours, 1 day, 1 week and 1 month. The intrabar resolution must of course be smaller than the chart’s resolution.
- Contrary to my other indicators where alerts must be configured to trigger “Once Per Bar Close” in order to avoid false triggers (or repainting), all this indicator’s alerts are designed to trigger using previous bar information since the indicator’s calculations in the realtime bar are not exact. Markers are not plotted with a negative offset; they appear at the beginning of the realtime bar following confirmation of the marker’s condition on the previous bar. Alerts for this indicator should thus be configured to trigger “Once Per Bar” so they trigger at the beginning of the realtime bar. Note that the penalty is not that great, as it is simply the instant between the close of the previous realtime bar and the opening of the next. The advantage of using this technique is that the indicator does not repaint; a marker that appears at the beginning of the realtime bar will never disappear.
- The script only plots information that is reliable in the realtime bar, i.e., total volume and markers. All other plots are set to n/a to prevent misleading traders.
- When the difference between the chart’s resolution and the lower resolution is too important, volume columns will not calculate for all bars in the dataset.

On Delta Volume
Buying or selling volume are misnomers, as every unit of volume transacted is both bought and sold by 2 different traders. There is no such thing as “buy only” or “sell only” volume, but trader lingo is riddled with original fabulations.
Without access to order book information, traders work with the assumption that when price moves up during a bar, there was more buying pressure than selling pressure. The built-in volume indicator available on TradingView uses this logic to color the volume columns green or red. While this script’s numbers are more precise because it analyses a number of intrabars to calculate its information, it uses the exact same imperfect logic to calculate its buying/selling/neutral sections.
Until Pine scripts can have access to how much volume was transacted at the bid/ask prices, our so-called buying/selling volume information will always be a mere proxy.

Divergences
You may wonder how there can be divergences between buying/selling volume information and price movement. This will sometimes be due to the methodology’s shortcomings we have just discussed, but divergences may also occur in instances where because of order book structure, it takes less volume to increase the price of an asset than it takes to decrease it.
As usual, divergences are points of interest because they reveal imbalances, which may or may not become turning points. I do not share the overwhelming enthusiasm traders have for divergences. To your pattern-hungry brain, the orange bars this indicator shows on chart will—as divergences on other indicators do–appear to often indicate turnarounds. My opinion is that reality is generally quite sobering, as many who have tried building automated rules based on divergences will tell you. I do not have hard numbers on the lack of performance of divergences—only many failed attempts to make them perform, which a few experienced strategy modelers I know share with me. Please don’t try to read too much into them. While they look great on past data, I find they are often difficult to use in realtime to make bets with good odds.

Thanks to:
- A guy called Kuan who commented on a Backtest Rookies presentation of an intrabar delta volume indicator using a for loop. The heart of “my” indicator is code borrowed from Kuan; I just built a hopefully useful wrapper around it.
- theheirophant, my partner in the exploration of the sometimes weird abysses of security()’s behavior at lower resolutions.
リリースノート
Updated comments and improved display on unsupported chart resolutions.
リリースノート
Disabled alerts. While plotted markers are reliable, alerts configured to trigger "Once Per Bar" are not.
リリースノート
Using "security()" on intrabars is not recommended by TradingView. While it works OK for this indicator most of the time, on charts for stocks at 1D and more, intrabar volume calculations are not reliable. I have introduced a volume calculation failure detection which is on by default and displays a red background when the sum of intrabar volume is off by a user-defined percentage. Failures will occasionally occur on other types of instruments and resolutions. This segment of a BTCUSD chart shows one such failure in the middle of the chart.

I have also deleted the alert code that had been commented out, as no fix can be hoped for in the foreseeable future. Markers are still reliable though.
リリースノート
v 1.5
• The volume columns of the realtime bar, as well as elapsed realtime bars that have not yet been calculated, have been made more visually prominent. You can see some of those elapsed columns to the right of this chart. They are light gray. This was done so that users who do not understand that the indicator only works on historical bars can have a cue as to what's going on.
• Automatically calculated lower intrabar resolutions derived from the chart's resolution can now be selected in one of 2 modes. You can still use a fixed resolution if you wish.
• Markers now show on the bar where they are detected. As they will not show on the realtime bar and cannot be used for alert generation, there was no sense in continuing to delay them on historical bars.
• Support for 3min resolution was added.
• The indicator's Inputs have been streamlined.
• Traders interested in a broader set of calculations and different ways of presenting them may want to look at:
Delta Volume Columns Pro
Delta Volume Columns Pro [LucF]

• For an overlay version of Delta Volume, see my:
Delta Volume Candles
Delta Volume Candles [LucF]


I will continue to maintain this simpler code base of Delta Volume Columns, as it already has many users and has the advantage of having Inputs which respond faster than more complex, two other versions above.
リリースノート
v6.0
This is a significant release. Because Release Notes allow for a limited length of text, the release's notes are spread over two updates: v6.0 and v7.0. The code is the same in both.

The following improvements were made:
 • A realtime calculation mode was added.
 • Divergences are now calculated using different methods, depending on the display mode used.
 • A new display mode showing Relative Delta Volume was added.
 • Alerts can now be configured on the script.
 • Inputs were streamlined and now contain tooltips showing more information on some of the inputs.


Realtime Mode
The script now works in realtime. This mode uses a completely different calculation method of Buy/Sell/Neutral volume than what is used on historical bars. Instead of intrabar inspection, which doesn't work in realtime, realtime mode uses a new Pine feature to calculate directional volume between volume/price updates during the realtime bars. Note that these updates are not the same as exchange ticks, as multiple exchange ticks can be aggregated in one TradingView price/volume update. When price increases between two realtime updates, the accrued volume between those updates is considered buying volume. If price does not change, then the volume is added to the neutral slot.

Realtime mode is interesting because it also allows the script to work on any timeframe. Certain precautions are required when interpreting data gathered during realtime bars:
 1. While the script is still gathering Buy/Sell/Neutral volume, it is calculated using a different way, so the transition between historical bars and realtime bars will sometimes be bumpy.
 2. Because realtime mode uses the volume data at the chart's timeframe, this means that on markets where end of day and intraday volume data differs
  (i.e., markets where the "Show Intraday/Daily Volume Discrepancies" input setting will display a red background),
  realtime calculations will typically be using much larger volume data than that used on historical bars if they are using an intraday intrabar timeframe.
  This may cause important variations in the scale of values between historical and realtime bars.
 3. If you refresh your chart or change inputs, which will force re-execution of the script, elapsed realtime bars will recalculate as historical bars, so using intrabar information.
  Your elapsed realtime bar calculations on the chart will thus be lost.

A small dot appears on the zero line to distinguish bars calculated in realtime mode from historical bars. If you hover over the dot, a tooltip will display the number of realtime updates used to calculate delta volume on that bar. The more updates, the more reliable the information will be.

If you plan on using the indicator at chart timeframes that are not supported by the intrabar inspection calculations used on historical bars, you can turn the "Show Error Messages" input off.


Divergences
In previous versions, divergences were always calculated by comparing the values of the Buy/Sell volume on a bar with the direction of price on that bar. This mode is still used whenever columns are displayed. If, however, only the "Volume Balance MA Delta" or "Relative Delta Volume" signals are displayed, divergences occur when the signal's direction does not match the direction of the bar. As before, you can choose to display divergences in the indicator's pane, on chart bars, or both.
リリースノート
v7.0
This is a significant release. Because Release Notes allow for a limited length of text, the release's notes are spread over two updates: v6.0 and v7.0. The code is the same in both.

Relative Delta Volume
This new display mode, which you can select from the "Main Display" input, is calculated as follows:
 • The reference values used in the calculation are the individual MAs for the Buy and Sell volume, which the indicator already uses to calculate the "Volume Balance MA Delta".
 • We then calculate two intermediate values using how much the instant Buy and Sell volumes on the bar exceed their respective reference MA.
  If the bar's Buy volume does not exceed the MA of Buy volume, a zero value is used. The same goes for the Sell volume with the MA of Sell volume.
 • Once we have our two intermediate values for the Buy and Sell volumes exceeding their respective MA, we subtract them.

If neither the Buy nor the Sell volumes on the bar exceed their MA, the signal's value is zero. The rationale behind this choice is that we only take into account the Buy or Sell volume when it is judged to be significant, i.e., above its respective MA. If both values exceed their MA, then the difference between the two is the signal's value. The signal is called "relative" because the intermediate values are the difference between the instant Buy/Sell volumes and their respective MA.

The "Relative Delta Volume" flatlines when the bar's Buy/Sell volumes do not exceed their MAs, which makes it useful to spot areas where trader interest dwindles, such as consolidations. These zones should be considered no-trade zones. Spikes often indicate stopping volume, coinciding with or leading reversals.

The signal uses the same coloring scheme as the "Volume Balance MA Delta". The fill is a brighter green when the signal is advancing. Zero values are plotted in gray. Because the same MAs as the ones used in "Volume Balance MA Delta" are also used in these calculations, they use the "Buy/Sell Volume Balance MA Period" from the inputs, which is "30" by default.


Alerts
The script uses the new alert() function to trigger alert events. This means that when you create an alert on this script from your chart, you will select the "Any alert() function call" condition. The set of conditions that will trigger your alert is determined by the markers you have enabled in the script's inputs before creating your alert. Once an alert is created its triggering conditions cannot be changed. If you want to reconfigure the conditions triggering the alert, delete the old one, configure your markets as you wish, then create a new alert. You can configure different alerts on the script, each using distinct triggering conditions.

Neither the markers nor the alerts will repaint. Markers only display—and alerts only trigger—at the close of the bar where the required conditions are met.
If more than one marker triggers an alert, the alert's message will contain identifiers for all the markers whose conditions were met at that time.
You can safely ignore the repainting warning that appears when you create an alert on this script, as it is overly conservative in the criteria it uses.
deltaVolume IndicatorVolume

オープンソーススクリプト

TradingViewの精神に則り、このスクリプトの作者は、トレーダーが理解し検証できるようにオープンソースで公開しています。作者に敬意を表します!無料で使用することができますが、このコードを投稿で再利用するには、ハウスルールに準拠する必要があります。 お気に入りに登録してチャート上でご利用頂けます。

チャートでこのスクリプトを利用したいですか?


"The stock market is a device for transferring money from the impatient to the patient."
— Buffet

tradingview.com/u/PineCoders/
tradingview.com/u/TradingView/
他のメディア:

免責事項