Selezione editorialeOPEN-SOURCE SCRIPT

Delta Volume Channels [LucF]

Aggiornato
█ OVERVIEW


This indicator displays on-chart visuals aimed at making the most of delta ​volume information. It can color bars and display two channels: one for delta ​volume, another calculated from the price levels of bars where delta ​volume divergences occur. Markers and alerts can also be configured using key conditions, and filtered in many different ways. The indicator caters to traders who prefer chart visuals over raw values. It will work on historical bars and in real time, using intrabar analysis to calculate delta ​volume in both conditions.



█ CONCEPTS


Delta Volume

​The ​volume delta concept divides a bar's ​volume in "up" and "down" ​volumes. The delta is calculated by subtracting down ​volume from up ​volume. Many calculation techniques exist to isolate up and down ​volume within a bar. The simplest techniques use the polarity of interbar price changes to assign their ​volume to up or down slots, e.g., On Balance Volume or the Klinger Oscillator. Others such as Chaikin Money Flow use assumptions based on a bar's OHLC values. The most precise calculation method uses tick data and assigns the ​volume of each tick to the up or down slot depending on whether the transaction occurs at the bid or ask price. While this technique is ideal, it requires huge amounts of data on historical bars, which usually limits the historical depth of charts and the number of symbols for which tick data is available.

This indicator uses intrabar analysis to achieve a compromise between the simplest and most precise methods of calculating ​volume delta. In the context where historical tick data is not yet available on TradingView, intrabar analysis is the most precise technique to calculate ​volume delta on historical bars on our charts. TradingView's Volume Profile built-in indicators use it, as do the CVD - Cumulative ​Volume Delta Candles and CVD - Cumulative Volume Delta (Chart) indicators published from the TradingView account. My Volume Delta Columns Pro indicator also uses intrabar analysis. Other ​volume delta indicators such as my Realtime 5D Profile use realtime chart updates to achieve more precise ​volume delta calculations. Indicators of that type cannot be used on historical bars however; they only work in real time.

This is the logic I use to assign intrabar ​volume to up or down slots:
 • If the intrabar's open and close values are different, their relative position is used.
 • If the intrabar's open and close values are the same, the difference between the intrabar's close and the previous intrabar's close is used.
 • As a last resort, when there is no movement during an intrabar and it closes at the same price as the previous intrabar, the last known polarity is used.

Once all intrabars making up a chart bar have been analyzed and the up or down property of each intrabar's ​volume determined, the up volumes are added and the down volumes subtracted. The resulting value is ​volume delta for that chart bar, which can be used as an estimate of the buying/selling pressure on an instrument.


Delta ​Volume Percent (DV%)

This value is the proportion that delta ​volume represents of the total intrabar ​volume in the chart bar. Note that on some symbols/timeframes, the total intrabar ​volume may differ from the chart's ​volume for a bar, but that will not affect our calculations since we use the total intrabar ​volume.


Delta ​Volume Channel

The ​​DV channel is the space between two moving averages: the reference line and a DV%-weighted version of that reference. The reference line is a moving average of a type, source and length which you select. The DV%-weighted line uses the same settings, but it averages the DV%-weighted price source.

The weight applied to the source of the reference line is calculated from two values, which are multiplied: DV% and the relative size of the bar's ​volume in relation to previous bars. The effect of this is that DV% values on bars with higher total ​volume will carry greater weight than those with lesser ​volume.

The ​DV channel can be in one of four states, each having its corresponding color:
 • Bull (teal): The DV%-weighted line is above the reference line.
 • Strong bull (lime): The bull condition is fulfilled and the bar's close is above the reference line and both the reference and the DV%-weighted lines are rising.
 • Bear (maroon): The DV%-weighted line is below the reference line.
 • Strong bear (pink): The bear condition is fulfilled and the bar's close is below the reference line and both the reference and the DV%-weighted lines are falling.


Divergences

In the context of this indicator, a divergence is any bar where the slope of the reference line does not match that of the DV%-weighted line. No directional bias is assigned to divergences when they occur.


Divergence Channel

The divergence channel is the space between two levels (by default, the bar's low and high) saved when divergences occur. When price has breached a channel and a new divergence occurs, a new channel is created. Until that new channel is breached, bars where additional divergences occur will expand the channel's levels if the bar's price points are outside the channel.

Prices breaches of the divergence channel will change its state. Divergence channels can be in one of five different states:
 • Bull (teal): Price has breached the channel to the upside.
 • Strong bull (lime): The bull condition is fulfilled and the ​DV channel is in the strong bull state.
 • Bear (maroon): Price has breached the channel to the downside.
 • Strong bear (pink): The bear condition is fulfilled and the ​DV channel is in the strong bear state.
 • Neutral (gray): The channel has not been breached.



█ HOW TO USE THE INDICATOR


Load the indicator on an active chart (see here if you don't know how).

The default configuration displays:
 • The ​DV channel, without the reference or DV%-weighted lines.
 • The Divergence channel, without its level lines.
 • Bar colors using the state of the ​DV channel.

The default settings use an Arnaud-Legoux moving average on the close and a length of 20 bars. The DV%-weighted version of it uses a combination of DV% and relative ​volume to calculate the ultimate weight applied to the reference. The DV%-weighted line is capped to 5 standard deviations of the reference. The lower timeframe used to access intrabars automatically adjusts to the chart's timeframe and achieves optimal balance between the number of intrabars inspected in each chart bar, and the number of chart bars covered by the script's calculations.

The Divergence channel's levels are determined using the high and low of the bars where divergences occur. Breaches of the channel require a bar's low to move above the top of the channel, and the bar's high to move below the channel's bottom.

No markers appear on the chart; if you want to create alerts from this script, you will need first to define the conditions that will trigger the markers, then create the alert, which will trigger on those same conditions.

To learn more about how to use this indicator, you must understand the concepts it uses and the information it displays, which requires reading this description. There are no videos to explain it.



█ FEATURES


The script's inputs are divided in four sections: "DV channel", "Divergence channel", "Other Visuals" and "Marker/Alert Conditions". The first setting is the selection method used to determine the intrabar precision, i.e., how many lower timeframe bars (intrabars) are examined in each chart bar. The more intrabars you analyze, the more precise the calculation of DV% results will be, but the less chart coverage can be covered by the script's calculations.


DV Channel

Here, you control the visibility and colors of the reference line, its weighted version, and the DV channel between them.

You also specify what type of moving average you want to use as a reference line, its source and length. This acts as the ​DV channel's baseline. The DV%-weighted line is also a moving average of the same type and length as the reference line, except that it will be calculated from the DV%-weighted source used in the reference line. By default, the DV%-weighted line is capped to five standard deviations of the reference line. You can change that value here. This section is also where you can disable the relative ​volume component of the weight.


Divergence Channel

This is where you control the appearance of the divergence channel and the key price values used in determining the channel's levels and breaching conditions. These choices have an impact on the behavior of the channel. More generous level prices like the default low and high selection will produce more conservative channels, as will the default choice for breach prices.

In this section, you can also enable a mode where an attempt is made to estimate the channel's bias before price breaches the channel. When it is enabled, successive increases/decreases of the channel's top and bottom levels are counted as new divergences occur. When one count is greater than the other, a bull/bear bias is inferred from it.


Other Visuals

You specify here:
 • The method used to color chart bars, if you choose to do so.
 • The display of a mark appearing above or below bars when a divergence occurs.
 • If you want raw values to appear in tooltips when you hover above chart bars. The default setting does not display them, which makes the script faster.
 • If you want to display an information box which by default appears in the lower left of the chart.
  It shows which lower timeframe is used for intrabars, and the average number of intrabars per chart bar.


Marker/Alert Conditions

Here, you specify the conditions that will trigger up or down markers. The trigger conditions can include a combination of state transitions of the ​DV and the divergence channels. The triggering conditions can be filtered using a variety of conditions.

Configuring the marker conditions is necessary before creating an alert from this script, as the alert will use the marker conditions to trigger.

Markers only appear on bar closes, so they will not repaint. Keep in mind, when looking at markers on historical bars, that they are positioned on the bar when it closes — NOT when it opens.


Raw values

The raw values calculated by this script can be inspected using a tooltip and the Data Window. The tooltip is visible when you hover over the top of chart bars. It will display on the last 500 bars of the chart, and shows the values of ​DV, DV%, the combined weight, and the intermediary values used to calculate them.



█ INTERPRETATION


The aim of the ​DV channel is to provide a visual representation of the buying/selling pressure calculated using delta ​volume. The simplest characteristic of the channel is its bull/bear state. One can then distinguish between its bull and strong bull states, as transitions from strong bull to bull states will generally happen when buyers are losing steam. While one should not infer a reversal from such transitions, they can be a good place to tighten stops. Only time will tell if a reversal will occur. One or more divergences will often occur before reversals.

The nature of the divergence channel's design makes it particularly adept at identifying consolidation areas if its settings are kept on the conservative side. A gray divergence channel should usually be considered a no-trade zone. More adventurous traders can use the ​DV channel to orient their trade entries if they accept the risk of trading in a neutral divergence channel, which by definition will not have been breached by price.

If your charts are already busy with other stuff you want to hold on to, you could consider using only the chart bar coloring component of this indicator:

istantanea

At its simplest, one way to use this indicator would be to look for overlaps of the strong bull/bear colors in both the ​DV channel and a divergence channel, as these identify points where price is breaching the divergence channel when buy/sell pressure is consistent with the direction of the breach. I have highlighted all those points in the chart below. Not all of them would have produced profitable trades, but nothing is perfect in the markets. Also, keep in mind that the circles identify the visual you would be looking for — not the trade's entry level.

istantanea



█ LIMITATIONS


 • The script will not work on symbols where no ​volume is available. An error will appear when that is the case.
 • Because a maximum of 100K intrabars can be analyzed by a script, a compromise is necessary between the number of intrabars analyzed per chart bar
  and chart coverage. The more intrabars you analyze per chart bar, the less coverage you will obtain.
  The setting of the "Intrabar precision" field in the "DV channel" section of the script's inputs
  is where you control how the lower timeframe is calculated from the chart's timeframe.



█ NOTES


Volume Quality
If you use ​volume, it's important to understand its nature and quality, as it varies with sectors and instruments. My Volume X-ray indicator is one way you can appraise the quality of an instrument's intraday ​volume.


For Pine Script™ Coders

 • This script uses the new overload of the fill() function which now makes it possible to do vertical gradients in Pine. I use it for both channels displayed by this script.
 • I use the new arguments for plot()'s `display` parameter to control where the script plots some of its values,
  namely those I only want to appear in the script's status line and in the Data Window.
 • I wrote my script using the revised recommendations in the Style Guide from the Pine v5 User Manual.



█ THANKS


To PineCoders. I have used their lower_tf library in this script, to manage the calculation of the LTF and intrabar stats, and their Time library to convert a timeframe in seconds to a printable form for its display in the Information box.

To TradingView's Pine Script™ team. Their innovations and improvements, big and small, constantly expand the boundaries of the language. What this script does would not have been possible just a few months back.

And finally, thanks to all the users of my scripts who take the time to comment on my publications and suggest improvements. I do not reply to all but I do read your comments and do my best to implement your suggestions with the limited time that I have.
Note di rilascio
v2
Fixed typos in comments.
Note di rilascio
v3
Improved some input tooltips and code aesthetics. No functional changes.
Note di rilascio
v4
• Reorganized the script's settings.
• Refactored minor bits of code.
• The tooltip showing raw values when you hover over the top of bars has been disabled by default because the script will be faster this way. You can enable them in the "Other Visuals" section of the inputs.
Note di rilascio
v5

Seconds intrabars

The script can now access seconds intrabar timeframes to calculate Delta Volume, which means that you can use it on small timeframes such as 1min or 30sec, where it will typically use 1sec intrabars. The intrabar timeframe used on a given symbol and timeframe will be calculated automatically for you, using one of ten preferences you can select from in the "Intrabars (LTF)" section of the script's inputs. The default setting attempts to obtain ~50 intrabars. Note that the actual number of intrabars will vary depending on whether the market is a 24H market or not, and its liquidity. Active markets are more likely to generate enough intrabars.

The information box appearing by default in the lower-right corner of the display was improved. In addition to the intrabar timeframe used, it displays the average number of intrabars discovered per chart bar, and the percentage of historical chart bars covered by calculations. As usual, the limit of 100K intrabars accessible by the script means that the more precise your calculations are because you are using more intrabars, the less chart bars the calculations will cover.

When less than 5 intrabars exist for chart bars, a warning will appear in the information box and its background will become red to indicate that calculations are not very reliable then.


Other changes

• Some functions local to the script were eliminated by using calls to those of my "ta" library.
• The information box displays more information than before.
volumedelta

Script open-source

In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?


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

tradingview.com/u/PineCoders/
tradingview.com/u/TradingView/
Anche su:

Declinazione di responsabilità