Category Volatility  Published on 19/04/2020

PVSRA Bars

Description

Bar volume color indicator of PVSRA


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class PVSRABars : Indicator
    {
        [Parameter("LookBack", DefaultValue = 10)]
        public int LookBack { get; set; }

        [Parameter("Bullish Normal", DefaultValue = "FF9FA0A2")]
        public string BullNormalVolume { get; set; }

        [Parameter("Bullish Normal", DefaultValue = "FF6A6A75")]
        public string BearNormalVolume { get; set; }

        [Parameter("Bullish Climax", DefaultValue = "FF1FC047")]
        public string BullClimaxVolume { get; set; }

        [Parameter("Bearish Climax", DefaultValue = "FFE00106")]
        public string BearClimaxVolume { get; set; }

        [Parameter("Bullish Rising", DefaultValue = "FF1188FF")]
        public string BullRisingVolume { get; set; }

        [Parameter("Bearish Rising", DefaultValue = "FFAD0FFF")]
        public string BearRisingVolume { get; set; }

        private Color colorBullNormalVolume;
        private Color colorBearNormalVolume;
        private Color colorBullClimaxVolume;
        private Color colorBearClimaxVolume;
        private Color colorBullRisingVolume;
        private Color colorBearRisingVolume;

        protected override void Initialize()
        {
            colorBullNormalVolume = GetColor(BullNormalVolume);
            colorBearNormalVolume = GetColor(BearNormalVolume);
            colorBullClimaxVolume = GetColor(BullClimaxVolume);
            colorBearClimaxVolume = GetColor(BearClimaxVolume);
            colorBullRisingVolume = GetColor(BullRisingVolume);
            colorBearRisingVolume = GetColor(BearRisingVolume);
        }

        public override void Calculate(int index)
        {
            var open = Bars.OpenPrices[index];
            var high = Bars.HighPrices[index];
            var low = Bars.LowPrices[index];
            var close = Bars.ClosePrices[index];
            var volume = Bars.TickVolumes[index];
            var isBullish = close > open;
            double av = 0;
            int va = 0;

            if (close >= open)
            {
                Chart.SetBarColor(index, colorBullNormalVolume);
            }
            else if (close < open)
            {
                Chart.SetBarColor(index, colorBearNormalVolume);
            }

            for (int n = 1; n <= LookBack; n++)
            {
                av += Bars.TickVolumes.Last(n);
            }
            av = av / LookBack;

            var range = high - low;
            var val = volume * range;
            double hiValue = 0;

            for (int n = 1; n <= LookBack; n++)
            {
                var temp = Bars.TickVolumes.Last(n) * (Bars.HighPrices.Last(n) - Bars.LowPrices.Last(n));
                if (temp >= hiValue)
                    hiValue = temp;
            }

            if (val >= hiValue || volume >= av * 2)
            {
                va = 1;
                Chart.SetBarColor(index, isBullish ? colorBullClimaxVolume : colorBearClimaxVolume);
            }

            if (va == 0 && volume >= av * 1.5)
            {
                va = 2;
                Chart.SetBarColor(index, isBullish ? colorBullRisingVolume : colorBearRisingVolume);
            }
        }

        private Color GetColor(string colorText)
        {
            try
            {
                return Color.FromHex(colorText);
            } catch
            {
                try
                {
                    return Color.FromName(colorText);
                } catch
                {
                    string errorObjName = string.Format("Your input for '{0}' parameter is incorrect", colorText);
                    Chart.DrawStaticText("Error", errorObjName, VerticalAlignment.Center, HorizontalAlignment.Center, Color.Red);
                    return Color.White;
                }
            }
        }

    }
}


reyx's avatar
reyx

Joined on 16.02.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: PVSRA Bars.algo
  • Rating: 5
  • Installs: 2439
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
PH
phaniophrero · 2 years ago

How can I remove the volume from to show on chart ? I only want to keep the candles with colors , but to remove that volume indicator.

PR
procumulative@gmail.com · 4 years ago

Hello, nice stuff...
Would u be able to do a VSA?

 

Mainly I am looking for inside, outside and breakout candles for HLC charts... 3 different colours...

EnzoCastelo's avatar
EnzoCastelo · 4 years ago

Gratidão por postar esse indicador de forma gratuita. Muito obrigado!

AJ
ajamalahm · 4 years ago

Hello my friend can you please fix code in C #? I converted a support and resistance indicator from mq4 to calqo at this site http://mq4tocalgo.apphb.com/CalgoToMQ4 and errors appeared because I am working on the c treder platform