Contents
Indicator Reference
Balance Of Power
Create Manual Indicators
You can manually create a BalanceOfPower
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 BalanceOfPower
constructor.
BalanceOfPower()1/2
BalanceOfPower QuantConnect.Indicators.BalanceOfPower ( )
Initializes a new instance of the BalanceOfPower
class using the specified name.
BalanceOfPower()2/2
BalanceOfPower QuantConnect.Indicators.BalanceOfPower (
string
name
)
Initializes a new instance of the BalanceOfPower
class using the specified name.
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 BalanceOfPower _bop; // In Initialize() _bop = new BalanceOfPower(name); _bop.Updated += IndicatorUpdateMethod; RegisterIndicator(symbol, _bop, Resolution.Daily); // In IndicatorUpdateMethod() if (_bop.IsReady) { var indicatorValue = _bop.Current.Value; }
# In Initialize() self.bop = BalanceOfPower(name) self.bop.Updated += self.IndicatorUpdateMethod self.RegisterIndicator(symbol, self.bop, Resolution.Daily) # In IndicatorUpdateMethod() if self.bop.IsReady: indicator_value = self.bop.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
, QuoteBar
, or an IndicatorDataPoint
. The indicator will only be ready after you prime it with enough data.
private BalanceOfPower _bop; private Symbol symbol; // In Initialize() _bop = new BalanceOfPower(); symbol = AddEquity("SPY").Symbol; // In OnData() if (data.QuoteBars.ContainsKey(_symbol)) { _bop.Update(data.QuoteBars[symbol]); } if (_bop.IsReady) { var indicatorValue = _bop.Current.Value; }
# In Initialize() self.bop = BalanceOfPower() self.symbol = self.AddEquity("SPY").Symbol # In OnData() if data.QuoteBars.ContainsKey(self.symbol): self.bop.Update(data.QuoteBars[self.symbol]) if self.bop.IsReady: indicator_value = self.bop.Current.Value
Create Automatic Indicators
The BOP method creates an BalanceOfPower 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 BOP
method:
BOP()1/1
BalanceOfPower QuantConnect.Algorithm.QCAlgorithm.BOP (Symbol
symbol,*Nullable<Resolution>
resolution,*Func<IBaseData, IBaseDataBar>
selector )
Creates a new Balance Of Power indicator. 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 BalanceOfPower _bop; // In Initialize() var symbol = AddEquity("SPY").Symbol; _bop = BOP(symbol); // In OnData() if (_bop.IsReady) { var current = _bop.Current.Value; }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.bop = self.BOP(symbol) # In OnData() if self.bop.IsReady: current = self.bop.Current.Value
Visualization
To plot indicator values, in the OnData
event handler, call the Plot
method.
private BalanceOfPower _bop; // In Initialize() var symbol = AddEquity("SPY").Symbol; _bop = BOP(symbol); // In OnData() if (_bop.IsReady) { Plot("My Indicators", "balanceofpower", _bop.Current); }
# In Initialize() symbol = self.AddEquity("SPY").Symbol self.bop = self.BOP(symbol) # In OnData() if self.bop.IsReady: self.Plot("My Indicators", "balanceofpower", self.bop.Current)
For more information about plotting indicators, see Plotting Indicators.