Table of Contents

Class MarketProfile

Namespace
Balsam
Assembly
Balsam.Backtester.dll

A class used to build a market profile.

public class MarketProfile : IEnumerable<TPO>, IEnumerable, ICloneable
Inheritance
MarketProfile
Implements
Inherited Members
Extension Methods

Constructors

MarketProfile(BarSeries)

Creates a new market profile using the specified BarSeries, where each tick between the high and low counts once.

public MarketProfile(BarSeries series)

Parameters

series BarSeries

MarketProfile(BarSeries, bool)

Creates a new market profile using the specified BarSeries and optionally tallies volume by price level rather than just having each price level count once.

public MarketProfile(BarSeries series, bool useVolume)

Parameters

series BarSeries
useVolume bool

MarketProfile(Instrument)

Creates an empty market profile using the specified instrument.

public MarketProfile(Instrument instrument)

Parameters

instrument Instrument

MarketProfile(TimeSeries, Instrument)

Creates a new market profile using the specified TimeSeries.

public MarketProfile(TimeSeries series, Instrument instrument)

Parameters

series TimeSeries
instrument Instrument

Properties

AvgCount

Gets the average number of TPO prints per price level.

public double AvgCount { get; }

Property Value

double

AvgPrice

Gets the average price of the distribution (not to be confused with the most frequent price or fair value.)

public double AvgPrice { get; }

Property Value

double

Bars

Gets the number of bars that were added to the profile.

public int Bars { get; }

Property Value

int

BuyImbalance

Gets the number of TPOs greater than fair value.

public double BuyImbalance { get; }

Property Value

double

Close

Gets the closing price of the distribution.

public double Close { get; }

Property Value

double

FairValue

Gets fair value or the most frequently traded price. In the event of a tie, the price level closest to the midpoint of the range is returned.

public double FairValue { get; }

Property Value

double

FirstDate

Gets/sets the first date used in the profile.

public DateTime FirstDate { get; set; }

Property Value

DateTime

High

Gets the maximum price of the distribution.

public double High { get; }

Property Value

double

HighVolumePrice

Gets the price at which the most volume traded.

public double HighVolumePrice { get; }

Property Value

double

InitialBalance

Gets the range of the initial bar used to build the profile.

public Range InitialBalance { get; }

Property Value

Range

Instrument

Gets the instrument on which the market profile is based. The Instrument's DecimalsToDisplay property is used to control rounding.

public Instrument Instrument { get; }

Property Value

Instrument

LastDate

Gets/sets the last date used in the profile.

public DateTime LastDate { get; set; }

Property Value

DateTime

Low

Gets the minimum price of the distribution.

public double Low { get; }

Property Value

double

MaxDensity

Gets the number of TPO prints that comprise the fair value price.

public int MaxDensity { get; }

Property Value

int

Midpoint

Gets the midpoint of the total range, rounded to the nearest tick. In the event of a tie, the value closest to fair value is returned.

public double Midpoint { get; }

Property Value

double

NetImbalance

Gets net buy/sell imbalance. Postive number indicates long-term buying pressure.

public double NetImbalance { get; }

Property Value

double

Open

Gets the opening price of the distribution.

public double Open { get; }

Property Value

double

PriceLevels

Gets the number of distinct price levels in the distribution.

public int PriceLevels { get; }

Property Value

int

Range

Gets the range or height of the total profile in points (High - Low).

public double Range { get; }

Property Value

double

RequiresVolume

Returns true when an Add method must be called with volume.

public bool RequiresVolume { get; }

Property Value

bool

SellImbalance

Gets the number of TPOs below fair value.

public double SellImbalance { get; }

Property Value

double

Symbol

Gets/sets the symbol.

public string Symbol { get; set; }

Property Value

string

TPOProfile

Gets the internal dictionary containing TPO counts with the price level as key.

protected SortedDictionary<double, double> TPOProfile { get; }

Property Value

SortedDictionary<double, double>

TotalDensity

Gets the number of TPOs comprising the profile.

public int TotalDensity { get; }

Property Value

int

TotalVolume

Gets the total volume of all points that comprise the profile. If volume was not used, this will match TotalDensity.

public double TotalVolume { get; }

Property Value

double

VWAP

Gets the volume weighted average price (calculated using the midpoint of a bar multiplied by that bar's volume).

public double VWAP { get; }

Property Value

double

VolumeProfile

Gets the internal dictionary containing volume with the price level as key.

protected SortedDictionary<double, double> VolumeProfile { get; }

Property Value

SortedDictionary<double, double>

Methods

Add(Bar)

Adds the specified bar using all price levels equally, ignoring volume.

public void Add(Bar bar)

Parameters

bar Bar

Add(Bar, bool)

Adds the specified bar allocating volume equally across all price levels.

public void Add(Bar bar, bool useVolume)

Parameters

bar Bar
useVolume bool

Add(TPO)

Adds the specified TPO to the profile.

public void Add(TPO tpo)

Parameters

tpo TPO

Add(double)

Adds the specified price level to the profile.

public void Add(double price)

Parameters

price double

Add(double, double)

Adds the specified price and associated volume to the profile.

public void Add(double price, double volume)

Parameters

price double
volume double

Bin(MarketProfile, int)

Returns a new market profile combining multiple price levels into one.

public static MarketProfile Bin(MarketProfile profile, int binSize)

Parameters

profile MarketProfile
binSize int

The number of price levels per bin.

Returns

MarketProfile

Clone()

Returns a clone of this market profile.

public MarketProfile Clone()

Returns

MarketProfile

FillGaps()

Fills in any gaps in the market profile with a zero frequency and returns the number of price levels inserted.

public int FillGaps()

Returns

int

GetCorrelationToNormal()

Returns the correlation of the first differences in the empirical and normal cdfs.

public double GetCorrelationToNormal()

Returns

double

GetCorrelationToUniform()

Returns the correlation of the first differences in the empirical and uniform cdfs.

public double GetCorrelationToUniform()

Returns

double

GetDensityAtPrice(double)

Returns the density value (number of TPO prints) at the specified price level.

public double GetDensityAtPrice(double price)

Parameters

price double

Returns

double

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<TPO> GetEnumerator()

Returns

IEnumerator<TPO>

GetMaximumDensity()

Returns the price with the maximum density within the value area.

public double GetMaximumDensity()

Returns

double

GetMaximumDensity(Range, double)

Returns the price with the maximum density within the specified range. Ties are broken by the distance to the tiebreaker level.

public double GetMaximumDensity(Range range, double tieBreaker)

Parameters

range Range
tieBreaker double

Returns

double

GetMinimumDensity(Range, double)

Returns the price with the minimum density within the specified range. Ties are broken by the distance to the tiebreaker level.

public double GetMinimumDensity(Range range, double tieBreaker)

Parameters

range Range
tieBreaker double

Returns

double

GetStandardDeviation()

Returns the standard deviation of TPO prices.

public double GetStandardDeviation()

Returns

double

GetTPOPivot(Range, double)

Returns the deepest pivot within the specified range subject to a minimum depth ratio. Returns NaN if none found.

public double GetTPOPivot(Range range, double depthRatio = 1)

Parameters

range Range
depthRatio double

Returns

double

GetTPOValueArea()

Returns a range that encompasses 70% of the TPO prints centered around fair value.

public Range GetTPOValueArea()

Returns

Range

GetTPOValueArea(double, int, double)

Returns a range that encompasses the specified percentage of the distribution centered around fair value.

public Range GetTPOValueArea(double percentage, int levels, double center)

Parameters

percentage double
levels int

The number of price levels to evaluate at a time.

center double

Returns

Range

GetTPOValueAreaPivot(double)

Returns the deepest pivot within the TPO value area surrounded by higher values or NaN if one doesn't exist.

public double GetTPOValueAreaPivot(double depthRatio = 1)

Parameters

depthRatio double

Returns

double

GetValueArea()

Returns the range exclusive of single TPO prints.

public Range GetValueArea()

Returns

Range

GetVolumeAtPrice(double)

Returns the volume at the specified price if the profile was built using volume.

public double GetVolumeAtPrice(double price)

Parameters

price double

Returns

double

GetVolumeProfile()

Returns an enumerable of TPOs representing the volume profile.

public IEnumerable<TPO> GetVolumeProfile()

Returns

IEnumerable<TPO>

GetVolumeValueArea()

Returns a range that encompasses 70% of the volume centered around the high volume price.

public Range GetVolumeValueArea()

Returns

Range

GetVolumeValueArea(double, int)

Returns a range that encompasses the specified percentage of total volume centered around the high volume price.

public Range GetVolumeValueArea(double percentage, int levels)

Parameters

percentage double
levels int

The number of price levels to evaluate at a time.

Returns

Range

Merge(MarketProfile)

Merges the specified profile into this one, returning a new combined profile.

public MarketProfile Merge(MarketProfile profile)

Parameters

profile MarketProfile

Returns

MarketProfile

Merge(params MarketProfile[])

Merges one or more market profiles into a new profile.

public static MarketProfile Merge(params MarketProfile[] profiles)

Parameters

profiles MarketProfile[]

Returns

MarketProfile