Category Oscilators  Published on 18/05/2023

Bulls Bears Power

Description

The Bulls Bears Power oscillator displays the power of bulls and bears, as well as their ratio.

In other words, when both indicator components, bulls (green) and bears (red), are above the zero level, the sentiment is very bullish. The bullish sentiment is considered to be in progress and continual if the bullish component (green) is above the up stop level (magenta).

Similarly, when both indicator components, bulls (green) and bears (red), are below the zero level, the sentiment is very bearish. The bearish sentiment is considered to be in progress and continual if the bearish component (red) is below the down stop level (magenta).

The up and down stop levels are determined by one of the Iba's modeling systems, which compares the consistency of the levels of bulls and bears.


using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
 
namespace cAlgo
{
    [Levels(0)]
    [Indicator(AccessRights = AccessRights.None)]
    public class mBullsBearsPower : Indicator
    {
        [Parameter("Periods (13)", DefaultValue = 13)]
        public int inpPeriods { get; set; }
        [Parameter("DataSeries (close)", DefaultValue = "Close")]
        public DataSeries inpdataSeries { get; set; }
         
        [Output("Bulls Power", LineColor = "Green", LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries outBullsPower { get; set; }
        [Output("Bears Power", LineColor = "Red", LineStyle = LineStyle.Solid, Thickness = 2)]
        public IndicatorDataSeries outBearsPower { get; set; }
        [Output("StopLevel Up", LineColor = "Magenta", LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outStopLevelUp { get; set; }
        [Output("StopLevel Dn", LineColor = "Magenta", LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outStopLevelDn { get; set; }
         
        private MovingAverage _pricesmooth;
        private IndicatorDataSeries _bulls, _bears, _stoplevelup, _stopleveldn;
         
 
        protected override void Initialize()
        {
            _pricesmooth = Indicators.MovingAverage(inpdataSeries, inpPeriods, MovingAverageType.Exponential);
            _bulls = CreateDataSeries();
            _bears = CreateDataSeries();
            _stoplevelup = CreateDataSeries();
            _stopleveldn = CreateDataSeries();
        }
 
        public override void Calculate(int i)
        {
            _bulls[i] = Bars.HighPrices[i] - _pricesmooth.Result[i];
            _bears[i] = Bars.LowPrices[i] - _pricesmooth.Result[i];
             
            _stoplevelup[i] = i<=inpPeriods ? 0 : _stoplevelup[i-1];
            if(i>inpPeriods && _bears[i-1]<0 && _bears[i]>0)
                _stoplevelup[i] = _bears[i];
            if(i>inpPeriods && _bears[i-1]>0 && _bears[i]>0)
                _stoplevelup[i] = Math.Max(_stoplevelup[i-1], _bears[i]);
             
            _stopleveldn[i] = i<=inpPeriods ? 0 : _stopleveldn[i-1];
            if(i>inpPeriods && _bulls[i-1]>0 && _bulls[i]<0)
                _stopleveldn[i] = _bulls[i];
            if(i>inpPeriods && _bulls[i-1]<0 && _bulls[i]<0)
                _stopleveldn[i] = Math.Min(_stopleveldn[i-1], _bulls[i]);
             
            outBullsPower[i] = _bulls[i];
            outBearsPower[i] = _bears[i];
            outStopLevelUp[i] = _stoplevelup[i];
            outStopLevelDn[i] = _stopleveldn[i];
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mBullsBearsPower.algo
  • Rating: 5
  • Installs: 511
Comments
Log in to add a comment.
No comments found.