Category Trend  Published on 04/02/2016

Bulls and Bears (v2)

Description

This Bulls and Bears indicator consolidates the Bulls and Bears Power sample indicators in one indicator.

Based on the original Bulls and Bears Power sample indicators from cTrade.

v2

+ Verbose: Allows the option to display the current values of Bulls and Bears.

v1

Public release

 


// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API consolidation indicator provided by njardim@email.com on Dec 2015.
//
//    Based on the original Bulls and Bears Power sample indicators from cTrade.
//
// -------------------------------------------------------------------------------------------------

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BullsandBears : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Verbose", DefaultValue = true)]
        public bool OnVerbose { get; set; }

        [Parameter(DefaultValue = 12, MinValue = 2)]
        public int Periods { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAType { get; set; }

        [Output("Bulls", Color = Colors.DodgerBlue, PlotType = PlotType.Histogram)]
        public IndicatorDataSeries Bulls { get; set; }

        [Output("Bears", Color = Colors.Red, PlotType = PlotType.Histogram)]
        public IndicatorDataSeries Bears { get; set; }

        private MovingAverage movingAverage;

        protected override void Initialize()
        {
            movingAverage = Indicators.MovingAverage(Source, Periods, MAType);
        }

        public override void Calculate(int index)
        {

            if (MarketSeries.High[index] - movingAverage.Result[index] > 0)
            {
                Bulls[index] = MarketSeries.High[index] - movingAverage.Result[index];
            }

            if (MarketSeries.Low[index] - movingAverage.Result[index] < 0)
            {
                Bears[index] = MarketSeries.Low[index] - movingAverage.Result[index];
            }

            if (OnVerbose)
            {

                if (MarketSeries.High[index] - movingAverage.Result[index] > 0.0001)
                {
                    var nBulls = String.Format("{0}", Math.Round(MarketSeries.High[index] - movingAverage.Result[index], Symbol.Digits));
                    ChartObjects.DrawText("Bulls", "Bulls: +" + nBulls + "\n \n", StaticPosition.BottomCenter, Colors.DodgerBlue);
                }
                else
                {
                    ChartObjects.DrawText("Bulls", "", StaticPosition.BottomCenter, Colors.DodgerBlue);
                }

                if (MarketSeries.Low[index] - movingAverage.Result[index] < -0.0001)
                {
                    var nBears = String.Format("{0}", Math.Round(MarketSeries.Low[index] - movingAverage.Result[index], Symbol.Digits));
                    ChartObjects.DrawText("Bears", "Bears: " + nBears, StaticPosition.BottomCenter, Colors.Red);
                }
                else
                {
                    ChartObjects.DrawText("Bears", "", StaticPosition.BottomCenter, Colors.Red);
                }
            }
        }
    }
}


NJ
njardim

Joined on 06.12.2015

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Bulls and Bears.algo
  • Rating: 5
  • Installs: 5422
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
AN
antrimagenciesllc · 2 years ago

But it is really interesting to read. | Metal Roof Repair Boise

AN
antrimagenciesllc · 2 years ago

This is a lot to take in. - Rancho Cordova Roof Installation

RA
rabaptista33 · 3 years ago

Muy bueno, Gracias

RA
rabaptista33 · 3 years ago

Muy bueno, Gracias

IT
itchiban · 3 years ago

thank you!!!! awesome stuff