Category Trend  Published on 15/04/2020

PVSRA Big Candles

Description

Big Candles indicator of PVSRA


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class PVSRABigCandles : Indicator
    {
        [Parameter("Time Frame", DefaultValue = "Hour4")]
        public TimeFrame CandleTimeFrame { get; set; }

        Bars bars;
        int lastBigCandleIndex;

        protected override void Initialize()
        {
            bars = MarketData.GetBars(CandleTimeFrame);
            lastBigCandleIndex = 0;
        }

        public override void Calculate(int index)
        {
            var lastIndex = bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            if (lastBigCandleIndex != lastIndex)
            {
                lastBigCandleIndex = lastIndex;
            }
            else
            {
                bool isUpper = bars.OpenPrices[lastIndex] < bars.ClosePrices[lastIndex];
                Color fillColor = Color.FromHex(isUpper ? "#AA001107" : "AA1E0B04");

                var startOfBar = Bars.OpenTimes.GetIndexByTime(bars.OpenTimes[lastBigCandleIndex]);

                var totalCandles = index - startOfBar;
                var wickWidth = (int)(totalCandles * 0.17);
                var middleIndex = startOfBar + (int)(totalCandles / 2) - (int)(wickWidth / 2);

                var body = Chart.DrawRectangle("CandleBody" + startOfBar, startOfBar, bars.OpenPrices[lastIndex], index, bars.ClosePrices[lastIndex], fillColor);
                body.IsFilled = true;
                body.ZIndex = 1;

                var topWick = Chart.DrawRectangle("CandleTopWick" + startOfBar, middleIndex, isUpper ? bars.ClosePrices[lastIndex] : bars.OpenPrices[lastIndex], middleIndex + wickWidth, bars.HighPrices[lastIndex], fillColor);
                topWick.IsFilled = true;
                topWick.ZIndex = 1;

                var bottomWick = Chart.DrawRectangle("CandleBottomWick" + startOfBar, middleIndex, isUpper ? bars.OpenPrices[lastIndex] : bars.ClosePrices[lastIndex], middleIndex + wickWidth, bars.LowPrices[lastIndex], fillColor);
                bottomWick.IsFilled = true;
                bottomWick.ZIndex = 1;
            }
        }
    }
}


reyx's avatar
reyx

Joined on 16.02.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: PVSRA Big Candles.algo
  • Rating: 5
  • Installs: 2018
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
No comments found.