Supported Indicators

Balance Of Power

Introduction

This indicator computes the Balance Of Power (BOP). The Balance Of Power is calculated with the following formula: BOP = (Close - Open) / (High - Low)

To view the implementation of this indicator, see the LEAN GitHub repository.

Using BOP Indicator

To create an automatic indicators for BalanceOfPower, call the BOP helper method from the QCAlgorithm class. The BOP method creates a BalanceOfPower object, hooks it up for automatic updates, and returns it so you can used it in your algorithm. In most cases, you should call the helper method in the Initializeinitialize method.

public class BalanceOfPowerAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private BalanceOfPower _bop;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _bop = BOP(_symbol);
    }

    public override void OnData(Slice data)
    {
        if (_bop.IsReady)
        {
            // The current value of _bop is represented by itself (_bop)
            // or _bop.Current.Value
            Plot("BalanceOfPower", "bop", _bop);
            
        }
    }
}
class BalanceOfPowerAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.bop = self.BOP(self.symbol)

    def on_data(self, slice: Slice) -> None:
        if self.bop.IsReady:
            # The current value of self.bop is represented by self.bop.Current.Value
            self.plot("BalanceOfPower", "bop", self.bop.Current.Value)
            

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 defaults 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.

For more information about plotting indicators, see Plotting 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.

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 Updateupdate method with a TradeBar or QuoteBar. The indicator will only be ready after you prime it with enough data.

public class BalanceOfPowerAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private BalanceOfPower _bop;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _bop = new BalanceOfPower();
    }

    public override void OnData(Slice data)
    {
        if (data.Bars.TryGetValue(_symbol, out var bar))
        {      
            _bop.Update(bar);
        }
   
        if (_bop.IsReady)
        {
            // The current value of _bop is represented by itself (_bop)
            // or _bop.Current.Value
            Plot("BalanceOfPower", "bop", _bop);
            
        }
    }
}
class BalanceOfPowerAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.bop = BalanceOfPower()

    def on_data(self, slice: Slice) -> None:
        bar = slice.Bars.get(self.symbol)
        if bar:
            self.bop.Update(bar)
        if self.bop.IsReady:
            # The current value of self.bop is represented by self.bop.Current.Value
            self.plot("BalanceOfPower", "bop", self.bop.Current.Value)
            

To register a manual indicator for automatic updates with the security data, call the RegisterIndicator method.

public class BalanceOfPowerAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private BalanceOfPower _bop;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _bop = new BalanceOfPower();
        RegisterIndicator(_symbol, _bop, Resolution.Daily);
    }

    public override void OnData(Slice data)
    {
        if (_bop.IsReady)
        {
            // The current value of _bop is represented by itself (_bop)
            // or _bop.Current.Value
            Plot("BalanceOfPower", "bop", _bop);
            
        }
    }
}
class BalanceOfPowerAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.bop = BalanceOfPower()
        self.RegisterIndicator(self.symbol, self.bop, Resolution.Daily)

    def on_data(self, slice: Slice) -> None:
        if self.bop.IsReady:
            # The current value of self.bop is represented by self.bop.Current.Value
            self.plot("BalanceOfPower", "bop", self.bop.Current.Value)
            

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.

Visualization

The following image shows plot values of selected properties of BalanceOfPower using the plotly library.

BalanceOfPower line plot.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: