Search Framework:
VolumeProfile
Namespace: WealthLab.Core
Parent: Object

The VolumeProfile class calculates a Volume Profile for a BarHistory over a specified lookback period. The profile divides the recent price range into a series of horizontal price bins represented by VolumeProfileItem instances. Each historical bar's volume is distributed across every profile bin intersected by that bar's High/Low range. The resulting profile can be used to identify the Point of Control, Value Area, and low-volume nodes above and below the Point of Control. For each source bar, WealthLab determines every profile price bin intersected by the bar's High/Low range. The bar's volume is divided equally among those bins. For example, if a bar contains volume of 100,000 and its price range overlaps four VolumeProfileItem bins, each bin receives 25,000 volume. The volume is added to either UpVolume or DownVolume depending on whether that source bar closed at or above the previous bar's Close. After volume has been distributed, WealthLab identifies the VolumeProfileItem with the greatest TotalVolume as the Point of Control. It then begins at the Point of Control and expands outward, adding neighboring profile bins to the Value Area until approximately ValueRangePct percent of total profile volume has been included. Finally, the relative width values of every VolumeProfileItem are calculated against the Point of Control's volume:

WidthPct     = TotalVolume / PointOfControlItem.TotalVolume;
WidthPctUp   = UpVolume    / PointOfControlItem.TotalVolume;
WidthPctDown = DownVolume  / PointOfControlItem.TotalVolume;

Consequently, the Point of Control has a WidthPct of 1.0, while lower-volume bins have proportionally smaller values.

public override void Initialize(BarHistory bars)
{
    VolumeProfile vp = new VolumeProfile(
        bars,
        252,
        50);
    DrawHorzLine(
        vp.PointOfControl,
        WLColor.Red,
        2);
    foreach (VolumeProfileItem item in vp.Items)
    {
        int width = (int)(100.0 * item.WidthPct);
        DrawLine(
            bars.Count - 1 - width,
            item.RangeMax,
            bars.Count - 1,
            item.RangeMax,
            item.InValueArea ? WLColor.Teal : WLColor.Gray,
            4);
    }
}
Constructors
VolumeProfile
public VolumeProfile(
BarHistory bars,
int lookback,
int barCount,
double valueRange = 70.0,
int? idx = null)

Creates a VolumeProfile using bars as the source data. lookback specifies the number of historical bars used in the calculation. The constructor constrains lookback as follows:

  • Values below 1 are changed to 1.
  • Values greater than the number of available bars are reduced to bars.Count. barCount specifies the desired number of horizontal price bins in the profile. WealthLab constrains this value to a minimum of 10 and a maximum of 500. The actual number of VolumeProfileItem instances can differ slightly from barCount because the profile price ranges are generated from the source data's minimum and maximum prices. valueRange specifies the percentage of total profile volume to include in the Value Area. It defaults to 70%. If idx is supplied, the initial Volume Profile is generated as of that BarHistory index. Otherwise, the profile is generated as of the final bar:
bars.Count - 1


Members
Bars
public BarHistory Bars

Gets or sets the BarHistory used to calculate the Volume Profile.


GenerateVolumeProfile
public void GenerateVolumeProfile(int idx)

Generates or regenerates the Volume Profile as of BarHistory index idx. The method first clears the existing Items collection. It determines the lowest Low and highest High over the current Lookback period ending at idx, and divides that range into approximately ProfileBarsDesired price bins. For each source bar in the lookback period, the bar's volume is distributed equally among all VolumeProfileItem ranges intersected by that bar's High/Low range. Volume is classified as up or down volume based on the bar's Close relative to the preceding bar's Close:

isUp = Bars.Close[i] >= Bars.Close[i - 1];

The profile then determines the Point of Control and Value Area and calculates the relative width values of each VolumeProfileItem. If Bars is null or idx is outside the available BarHistory, the method returns without generating a profile.


Items
public List<VolumeProfileItem> Items

Contains the horizontal price bins that make up the Volume Profile. Each VolumeProfileItem includes its price range, up and down volume, total volume, Value Area status, and relative width.


Lookback
public int Lookback

Gets or sets the number of source bars used when generating the Volume Profile. The default property value is 252. Changing Lookback does not automatically regenerate the profile. Call GenerateVolumeProfile after changing it.


LowVolNodeLower
public double LowVolNodeLower

Returns the price level of the lowest-volume profile bin below the Point of Control that was included in the Value Area. The value returned is the VolumeProfileItem's RangeMax.


LowVolNodeUpper
public double LowVolNodeUpper

Returns the price level of the lowest-volume profile bin above the Point of Control that was included in the Value Area. The value returned is the VolumeProfileItem's RangeMax.


PointOfControl
public double PointOfControl

Returns the price level corresponding to the profile bin with the greatest TotalVolume. The value returned is that VolumeProfileItem's RangeMax.


PointOfControlItem
public VolumeProfileItem PointOfControlItem

Returns the VolumeProfileItem having the greatest TotalVolume. The item is also marked with:

IsPOC = true
InValueArea = true

ProfileBarsDesired
public int ProfileBarsDesired

Gets or sets the desired number of horizontal price bins used when generating the Volume Profile. The default property value is 50. The actual number of Items can differ slightly depending on the source data's price range and the generated bin increment.


ValueRangePct
public double ValueRangePct

Gets or sets the percentage of total Volume Profile volume that WealthLab attempts to include in the Value Area. The default value is 70. The Value Area calculation begins with the Point of Control and then expands outward through neighboring VolumeProfileItem instances until the requested percentage of total profile volume has been included. Each included VolumeProfileItem has its InValueArea property set to true.