Contents
Indicator Reference
Volume Profile
Create Manual Indicators
You can manually create a VolumeProfile
indicator, so it doesn’t automatically update. Manual indicators let you update their values with any data you choose. The following reference table describes the VolumeProfile
constructor.
VolumeProfile()1/2
VolumeProfile QuantConnect.Indicators.VolumeProfile (
*int
period
)
Creates a new VolumeProfile indicator with the specified period.
VolumeProfile()2/2
VolumeProfile QuantConnect.Indicators.VolumeProfile (string
name,int
period,*decimal
priceRangeRoundOff )
Creates a new VolumeProfile indicator with the specified name, period and priceRangeRoundOff.
Update Manual Indicators
You can update the indicator automatically or manually.
Automatic Update
To register a manual indicator for automatic updates with the security data, call the RegisterIndicator
method.
private VolumeProfile _vp; // In Initialize() _vp = new VolumeProfile(name, period); _vp.Updated += IndicatorUpdateMethod; RegisterIndicator(symbol, _vp, Resolution.Daily); // In IndicatorUpdateMethod() if (_vp.IsReady) { var indicatorValue = _vp.Current.Value; }
# In Initialize() self.vp = VolumeProfile(name, period) self.vp.Updated += self.IndicatorUpdateMethod self.RegisterIndicator(symbol, self.vp, Resolution.Daily) # In IndicatorUpdateMethod() if self.vp.IsReady: indicator_value = self.vp.Current.Value
To customize the data that automatically updates the indicator, see Custom Indicator Periods and Custom Indicator Values.
Manual Update
Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Update
method with a TradeBar
. The indicator will only be ready after you prime it with enough data.
private VolumeProfile _vp; private Symbol symbol; // In Initialize() _vp = new VolumeProfile(period); symbol = AddEquity("SPY").Symbol; // In OnData() if (data.Bars.ContainsKey(_symbol)) { _vp.Update(data.Bars[symbol]); } if (_vp.IsReady) { var indicatorValue = _vp.Current.Value; }
# In Initialize() self.vp = VolumeProfile(period) self.symbol = self.AddEquity("SPY").Symbol # In OnData() if data.Bars.ContainsKey(self.symbol): self.vp.Update(data.Bars[self.symbol]) if self.vp.IsReady: indicator_value = self.vp.Current.Value
Create Automatic Indicators
The VP method creates an VolumeProfile indicator, sets up a consolidator to update the indicator, and then returns the indicator so you can use it in your algorithm.
The following reference table describes the VP
method:
VP()1/1
VolumeProfile QuantConnect.Algorithm.QCAlgorithm.VP (Symbol
symbol,*Int32
period,*Decimal
valueAreaVolumePercentage,*Decimal
priceRangeRoundOff,*Resolution
resolution,*Func<IBaseData, TradeBar>
selector )
Creates an Market Profile indicator for the symbol with Volume Profile (VOL) mode. The indicator will be automatically updated on the given resolution.
If you don't provide a resolution, it defauls to the security resolution. If you provide a resolution, it must be greater than or equal to the resolution of the security. For instance, if you subscribe to hourly data for a security, you should update its indicator with data that spans 1 hour or longer.
For more information about the selector argument, see Alternative Price Fields.
Get Indicator Values
To get the value of the indicator, use its Current.Value
attribute.
private VolumeProfile _vp; // In Initialize() var symbol = AddEquity("SPY").Symbol; _vp = VP(symbol); // In OnData() if (_vp.IsReady) { var volumePerPrice = _vp.VolumePerPrice.Current.Value; var profileHigh = _vp.ProfileHigh.Current.Value; var profileLow = _vp.ProfileLow.Current.Value; var pOCPrice = _vp.POCPrice.Current.Value; var pOCVolume = _vp.POCVolume.Current.Value; var valueAreaVolume = _vp.ValueAreaVolume.Current.Value; var valueAreaHigh = _vp.ValueAreaHigh.Current.Value; var valueAreaLow = _vp.ValueAreaLow.Current.Value; var current = _vp.Current.Value; }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.vp = self.VP(symbol) # In OnData() if self.vp.IsReady: volume_per_price = self.vp.VolumePerPrice.Current.Value profile_high = self.vp.ProfileHigh.Current.Value profile_low = self.vp.ProfileLow.Current.Value p_o_c_price = self.vp.POCPrice.Current.Value p_o_c_volume = self.vp.POCVolume.Current.Value value_area_volume = self.vp.ValueAreaVolume.Current.Value value_area_high = self.vp.ValueAreaHigh.Current.Value value_area_low = self.vp.ValueAreaLow.Current.Value current = self.vp.Current.Value
Visualization
To plot indicator values, in the OnData
event handler, call the Plot
method.
private VolumeProfile _vp; // In Initialize() var symbol = AddEquity("SPY").Symbol; _vp = VP(symbol); // In OnData() if (_vp.IsReady) { Plot("My Indicators", "volumeperprice", _vp.VolumePerPrice); Plot("My Indicators", "profilehigh", _vp.ProfileHigh); Plot("My Indicators", "profilelow", _vp.ProfileLow); Plot("My Indicators", "pocprice", _vp.POCPrice); Plot("My Indicators", "pocvolume", _vp.POCVolume); Plot("My Indicators", "valueareavolume", _vp.ValueAreaVolume); Plot("My Indicators", "valueareahigh", _vp.ValueAreaHigh); Plot("My Indicators", "valuearealow", _vp.ValueAreaLow); Plot("My Indicators", "volumeprofile", _vp.Current); }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.vp = self.VP(symbol) # In OnData() if self.vp.IsReady: self.Plot("My Indicators", "volumeperprice", self.vp.VolumePerPrice) self.Plot("My Indicators", "profilehigh", self.vp.ProfileHigh) self.Plot("My Indicators", "profilelow", self.vp.ProfileLow) self.Plot("My Indicators", "pocprice", self.vp.POCPrice) self.Plot("My Indicators", "pocvolume", self.vp.POCVolume) self.Plot("My Indicators", "valueareavolume", self.vp.ValueAreaVolume) self.Plot("My Indicators", "valueareahigh", self.vp.ValueAreaHigh) self.Plot("My Indicators", "valuearealow", self.vp.ValueAreaLow) self.Plot("My Indicators", "volumeprofile", self.vp.Current)
For more information about plotting indicators, see Plotting Indicators.