Custom Tick Chart (Non-overlay) free

by Spotware in category Other at 03/02/2022
Description

  This indicator allows you to create custom Tick charts by using the current available Tick chart on cTrader.

You can set the tick size to any value you want to, you can also attach the cTrader indicators on custom generated chart OHLC outputs.

Features

  • Creates custom size tick charts
  • Separate on chart and non-overlay versions
  • You can change the colors of bars
  • Shows the high/low wicks for bars
  • You can use the custom chart outputs as a source for other indicators

Changelog

Version 1.2.1.0

Release Date: June 1, 2022

Fixed: Issue with cTrader 4.2

Version 1.2.0.0

Release Date: May 27, 2022

Removed: Error messages

Added: Automatically changes the chart period to an appropriate Tick period that the custom tick chart can be generated from

Added: Making the actual chart bars transparent (only overlay version)

Fixed: Issue with attached indicators

Version 1.1.0.0

Release Date: May 26, 2022

Fixed: Outputs issue

 

This indicator is open source, if you want to contribute: 

 

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using cAlgo.API;
using System;
using System.Globalization;
using System.Linq;
using System.Collections.Generic;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class CustomTickChart : Indicator
    {
        #region Fields

        private const string Name = "Custom Tick Chart";

        private const string TimeFrameNamePrefix = "Tick";

        private string _chartObjectNamesSuffix;

        private CustomOhlcBar _lastBar, _previousBar;

        private Color _bullishBarBodyColor, _bullishBarWickColor, _bearishBarBodyColor, _bearishBarWickColor;

        private bool _isChartTypeValid;

        private Bars _bars;

        private int _timeFrameSizeRatio, _barNumber, _lastBarIndex = -1;

        private readonly List<CustomOhlcBar> _customBars = new List<CustomOhlcBar>();

        #endregion Fields

        #region Parameters

        [Parameter("Size(Ticks)", DefaultValue = 75, Group = "General")]
        public int SizeInTicks { get; set; }

        [Parameter("Bullish Bar Color", DefaultValue = "Lime", Group = "Body")]
        public string BullishBarBodyColor { get; set; }

        [Parameter("Bearish Bar Color", DefaultValue = "Red", Group = "Body")]
        public string BearishBarBodyColor { get; set; }

        [Parameter("Opacity", DefaultValue = 100, MinValue = 0, MaxValue = 255, Group = "Body")]
        public int BodyOpacity { get; set; }

        [Parameter("Thickness", DefaultValue = 1, Group = "Body")]
        public int BodyThickness { get; set; }

        [Parameter("Line Style", DefaultValue = LineStyle.Solid, Group = "Body")]
        public LineStyle BodyLineStyle { get; set; }

        [Parameter("Fill", DefaultValue = true, Group = "Body")]
        public bool FillBody { get; set; }

        [Parameter("Show", DefaultValue = true, Group = "Wicks")]
        public bool ShowWicks { get; set; }

        [Parameter("Bullish Bar Color", DefaultValue = "Lime", Group = "Wicks")]
        public string BullishBarWickColor { get; set; }

        [Parameter("Bearish Bar Color", DefaultValue = "Red", Group = "Wicks")]
        public string BearishBarWickColor { get; set; }

        [Parameter("Opacity", DefaultValue = 100, MinValue = 0, MaxValue = 255, Group = "Wicks")]
        public int WicksOpacity { get; set; }

        [Parameter("Thickness", DefaultValue = 2, Group = "Wicks")]
        public int WicksThickness { get; set; }

        [Parameter("Line Style", DefaultValue = LineStyle.Solid, Group = "Wicks")]
        public LineStyle WicksLineStyle { get; set; }

        [Parameter("Open", DefaultValue = true, Group = "OHLC Outputs")]
        public bool IsOpenOutputEnabled { get; set; }

        [Parameter("High", DefaultValue = true, Group = "OHLC Outputs")]
        public bool IsHighOutputEnabled { get; set; }

        [Parameter("Low", DefaultValue = true, Group = "OHLC Outputs")]
        public bool IsLowOutputEnabled { get; set; }

        [Parameter("Close", DefaultValue = true, Group = "OHLC Outputs")]
        public bool IsCloseOutputEnabled { get; set; }

        #endregion Parameters

        #region Other properties

        public ChartArea Area
        {
            get { return IndicatorArea ?? (ChartArea)Chart; }
        }

        #endregion Other properties

        #region Outputs

        [Output("Open", LineColor = "Transparent", PlotType = PlotType.Line)]
        public IndicatorDataSeries Open { get; set; }

        [Output("High", LineColor = "Transparent", PlotType = PlotType.Line)]
        public IndicatorDataSeries High { get; set; }

        [Output("Low", LineColor = "Transparent", PlotType = PlotType.Line)]
        public IndicatorDataSeries Low { get; set; }

        [Output("Close", LineColor = "Transparent", PlotType = PlotType.Line)]
        public IndicatorDataSeries Close { get; set; }

        #endregion Outputs

        #region Overridden methods

        protected override void Initialize()
        {
            _chartObjectNamesSuffix = string.Format("{0}_{1}", Name, DateTime.Now.Ticks);

            var timeFrameName = Chart.TimeFrame.ToString();

            timeFrameName = timeFrameName.Equals("tick", StringComparison.OrdinalIgnoreCase) ? "Tick1" : timeFrameName;

            if (timeFrameName.Equals(string.Format("Tick{0}", SizeInTicks), StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            else if (timeFrameName.StartsWith("Tick", StringComparison.Ordinal) && SizeInTicks % Convert.ToInt32(timeFrameName.Substring(TimeFrameNamePrefix.Length), CultureInfo.InvariantCulture) == 0)
            {
                _bars = Bars;
            }
            else
            {
                var timeFrame = GetTimeFrame(SizeInTicks, "tick");

                Chart.TryChangeTimeFrame(timeFrame);

                return;
            }

            _timeFrameSizeRatio = SizeInTicks / GetTimeFrameSize(_bars.TimeFrame.ToString(), TimeFrameNamePrefix);

            _isChartTypeValid = true;

            _bullishBarBodyColor = GetColor(BullishBarBodyColor, BodyOpacity);
            _bearishBarBodyColor = GetColor(BearishBarBodyColor, BodyOpacity);

            _bullishBarWickColor = GetColor(BullishBarWickColor, WicksOpacity);
            _bearishBarWickColor = GetColor(BearishBarWickColor, WicksOpacity);

            //Chart.ColorSettings.BullFillColor = Color.Transparent;
            //Chart.ColorSettings.BearFillColor = Color.Transparent;
            //Chart.ColorSettings.BullOutlineColor = Color.Transparent;
            //Chart.ColorSettings.BearOutlineColor = Color.Transparent;

            for (int barIndex = 0; barIndex < _bars.Count; barIndex++)
            {
                OnBar(barIndex);
            }

            _bars.BarOpened += obj => OnBar(obj.Bars.Count - 1);
        }

        public override void Calculate(int index)
        {
            var bar = _customBars.FirstOrDefault(iBar => Bars.OpenTimes[index] >= iBar.StartTime && Bars.OpenTimes[index] <= iBar.EndTime);

            if (bar == null) return;

            var startBarIndex = Bars.OpenTimes.GetIndexByTime(bar.StartTime);
            var endBarIndex = Bars.OpenTimes.GetIndexByTime(bar.EndTime);

            for (int barIndex = startBarIndex; barIndex <= endBarIndex + 1; barIndex++)
            {
                FillOutputs(barIndex, bar);
            }
        }

        #endregion Overridden methods

        #region Other methods

        private void OnBar(int index)
        {
            if (_isChartTypeValid == false) return;

            if (_lastBarIndex == index) return;

            _lastBarIndex = index;

            var time = _bars.OpenTimes[index];

            if (_lastBar == null || _barNumber == _timeFrameSizeRatio)
            {
                ChangeLastBar(time, index);

                _barNumber = 1;
            }
            else
            {
                _barNumber += 1;
            }

            for (int barIndex = _lastBar.Index; barIndex <= index; barIndex++)
            {
                UpdateLastBar(time, barIndex);
            }

            DrawBar(_lastBar);
        }

        private void FillOutputs(int index, CustomOhlcBar lastBar)
        {
            if (IsOpenOutputEnabled)
            {
                Open[index] = decimal.ToDouble(lastBar.Open);
            }

            if (IsHighOutputEnabled)
            {
                High[index] = decimal.ToDouble(lastBar.High);
            }

            if (IsLowOutputEnabled)
            {
                Low[index] = decimal.ToDouble(lastBar.Low);
            }

            if (IsCloseOutputEnabled)
            {
                Close[index] = decimal.ToDouble(lastBar.Close);
            }
        }

        private Color GetColor(string colorString, int alpha = 255)
        {
            var color = colorString[0] == '#' ? Color.FromHex(colorString) : Color.FromName(colorString);

            return Color.FromArgb(alpha, color);
        }

        private void DrawBar(CustomOhlcBar lastBar)
        {
            string objectName = string.Format("{0}.{1}", lastBar.StartTime.Ticks, _chartObjectNamesSuffix);

            var barBodyColor = lastBar.Open > lastBar.Close ? _bearishBarBodyColor : _bullishBarBodyColor;

            var open = decimal.ToDouble(lastBar.Open);
            var close = decimal.ToDouble(lastBar.Close);

            var bodyRectangle = Area.DrawRectangle(objectName, lastBar.StartTime, open, lastBar.EndTime, close, barBodyColor, BodyThickness, BodyLineStyle);

            bodyRectangle.IsFilled = FillBody;

            if (ShowWicks)
            {
                string upperWickObjectName = string.Format("{0}.UpperWick", objectName);
                string lowerWickObjectName = string.Format("{0}.LowerWick", objectName);

                var barHalfTimeInMinutes = (lastBar.EndTime - _lastBar.StartTime).TotalMinutes / 2;
                var barCenterTime = lastBar.StartTime.AddMinutes(barHalfTimeInMinutes);

                if (lastBar.Open > lastBar.Close)
                {
                    Area.DrawTrendLine(upperWickObjectName, barCenterTime, open, barCenterTime, decimal.ToDouble(lastBar.High), _bearishBarWickColor, WicksThickness, WicksLineStyle);
                    Area.DrawTrendLine(lowerWickObjectName, barCenterTime, close, barCenterTime, decimal.ToDouble(lastBar.Low), _bearishBarWickColor, WicksThickness, WicksLineStyle);
                }
                else
                {
                    Area.DrawTrendLine(upperWickObjectName, barCenterTime, close, barCenterTime, decimal.ToDouble(lastBar.High), _bullishBarWickColor, WicksThickness, WicksLineStyle);
                    Area.DrawTrendLine(lowerWickObjectName, barCenterTime, open, barCenterTime, decimal.ToDouble(lastBar.Low), _bullishBarWickColor, WicksThickness, WicksLineStyle);
                }
            }
        }

        private void ChangeLastBar(DateTime time, int index)
        {
            if (_lastBar != null)
            {
                DrawBar(_lastBar);
            }

            _previousBar = _lastBar;

            _lastBar = new CustomOhlcBar
            {
                StartTime = time,
                Index = index,
                Open = _previousBar == null ? (decimal)_bars.OpenPrices[index] : _previousBar.Close
            };

            _lastBar.Close = _lastBar.Open;
            _lastBar.High = _lastBar.Open;
            _lastBar.Low = _lastBar.Open;

            // Commented because it causes incompatibility issue with version 4.2
            //if (IsLastBar)
            //{
            //    _customBars.Clear();
            //}

            _customBars.Add(_lastBar);
        }

        private void UpdateLastBar(DateTime time, int index)
        {
            _lastBar.Close = (decimal)_bars.ClosePrices[index];
            _lastBar.High = Math.Max((decimal)_bars.HighPrices[index], _lastBar.High);
            _lastBar.Low = Math.Min((decimal)_bars.LowPrices[index], _lastBar.Low);
            _lastBar.EndTime = time;
            _lastBar.Index = index;
        }

        private TimeFrame GetTimeFrame(int sizeInPips, string type)
        {
            var timeFrames = (from timeFrame in TimeFrame.GetType().GetFields()
                              where timeFrame.Name.StartsWith(type, StringComparison.OrdinalIgnoreCase)
                              let timeFrameName = timeFrame.Name.Equals("tick", StringComparison.OrdinalIgnoreCase) ? "Tick1" : timeFrame.Name
                              let timeFrameSize = Convert.ToInt32(timeFrameName.Substring(type.Length))
                              where timeFrameSize <= sizeInPips && sizeInPips % timeFrameSize == 0
                              orderby timeFrameSize descending
                              select new Tuple<TimeFrame, int>(timeFrame.GetValue(null) as TimeFrame, timeFrameSize)).ToArray();

            var bestFitTimeFrame = timeFrames.FirstOrDefault(timeFrame => timeFrame.Item2 <= sizeInPips && sizeInPips % timeFrame.Item2 == 0);

            if (bestFitTimeFrame != null)
                return bestFitTimeFrame.Item1;

            var smallestTimeFrame = timeFrames.LastOrDefault();

            if (smallestTimeFrame != null)
                return smallestTimeFrame.Item1;

            throw new InvalidOperationException(string.Format("Couldn't find a proper time frame for your provided size ({0} Ticks) and type ({1}).", sizeInPips, type));
        }

        private int GetTimeFrameSize(string timeFrameName, string type)
        {
            return timeFrameName.Equals("tick", StringComparison.OrdinalIgnoreCase) ? 1 : Convert.ToInt32(timeFrameName.Substring(type.Length));
        }

        #endregion Other methods
    }

    public class CustomOhlcBar
    {
        public DateTime StartTime { get; set; }

        public DateTime EndTime { get; set; }

        public int Index { get; set; }

        public decimal Open { get; set; }

        public decimal High { get; set; }

        public decimal Low { get; set; }

        public decimal Close { get; set; }
    }
}
Comments

junaidraz278 - February 08, 2022 @ 15:28

I was not interested in trading before my friend introduce this to me. He told me that his profit margin is up to 15%, so, I started immediately:) Now my profile margin is up to 17%:) Highly recommended!

jameswilliamwriter - February 21, 2022 @ 09:05

Thanks for posting, as I've just stepped into the field of developing websites, will you please tell me about this whole content or what is this about actually? so I can add this in my assignment help usa website.

hoalai3493 - February 25, 2022 @ 19:59

Your article is very good and useful, thank you for sharing, bk8 hopes that next time you will have more good articles to send to all readers.

jameskramer2563429 - March 04, 2022 @ 22:13

If it's an online game, then choose a game that gives you the strongest feeling! Play happy wheels horror game now 

Urgot68 - March 09, 2022 @ 09:10

How it manages to be such a good games game? Easy, I love how Friday Night Funkin game is created to be a solidly built rhythm game with awesome features. ninjamuffin99 has successfully put efforts and engineered a sophisticated music software. Try it for yourself, I am pretty sure that you will like it too.

jacklinalbert12 - March 21, 2022 @ 13:03

I will visit your blog more often because bespoke web design UK would like to read more of your articles. Thanks for sharing a piece of great information that is very useful for us.

 

nobit2021 - July 07, 2022 @ 10:48

A good article, or a compelling story requires the author to have a keen sense and eye to have an in-depth look at it. I am very impressed with your article. nytimes crossword

prestigedecanter6 - July 14, 2022 @ 08:47

Nice article! i really like your blog is really awesome and cool appreciate your blog is really interesting and great.thanks for sharing the nice and cool post.

Bluetooth karaoke microphone

alecy773 - September 02, 2022 @ 15:54

Thanks for posting, as I've just stepped into the field of developing websites, will you please tell me about this whole content or what is this about actually? so I can add this in my assignment help USA website.hiketop+

junealexis001 - September 12, 2022 @ 12:14

Awesome  site i love it keep posting more!   storage sheds chattanooga tn

ashikasonimkt - September 21, 2022 @ 16:38

Bangalore Escorts provide By AshikaSoni. Here you get all type of Female Escort Call Girls at very affordable rate. We are offering College girl Escorts, models, celebrity escorts, housewife escorts, Russian escorts and Much more. Our Services is open 24/7. So If You are in Bangalore and spend your evening with hot looking female Bangalore Escort call girls. Visit the website.

Escorts in Bangalore

jennytrippi02 - September 22, 2022 @ 07:40

This indicator allows to create custom Tick charts using existing Tick charts on cTrader. C# trading platform looks quite complex, can be optimized like stickman boost?

codellamkt - October 13, 2022 @ 11:51

Available 24/7 Bangalore Escorts at Codella.here you get High Class VIP Bangalore Escort call Girls at Very affordable rate. So if you are in Bangalore and looking Escort call Girls then you are in write place. Our Female escorts are so hot and giving you naughty entertainment whole night. So Visit my website now for booking.

Bangalore Escort

Bangalore Escorts Service

Escorts in Bangalore

Bangalore Call Girls

Chennai Escorts

murtazan405 - October 13, 2022 @ 15:28

I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!.. Financial Advisor

aliyasen989858 - November 05, 2022 @ 08:09

My hot beauty GFE pleasures as female Call girl in Ludhiana

The only goal of the situation is to please her clients and to be our top model and expert college girls. She greets them with warm eyes and a smile when they meet their clients. Within a few minutes, you are familiar with her.

You will not feel like meeting with her for the first time. We suggest that our Russian female Call girls in Ludhiana once you become a friend. After that, without wasting your time, she begins to provide you with every kind of pleasure that you desire and fulfils your desire with sexy and soft fashion, and after you, through our model, we assure you that you'll never are disappointed to think the moment when you see a smile on your face. Now you get to meet your beautiful girlfriend with a smile in independent Ludhiana Call girls services and enjoy your precious moment of love.

It is said that the book my babes is a group of high-end Ludhiana Call girls that are which are located in Punjab. Straight couple experiences mean that your Ludhiana Call girl will focus on her body's attention only towards the male. The Ludhiana college girl friendship experience is a more intimate kind of experience.

This website has themes that are for adults and is intended for those who are 18 or over. If you're sensitive to adult content, please go away immediately. Available from 10 am to late, seven days a week.

Panchkula Call girls, Zirakpur Call girls, Mohali Call girls

natasharoybd - November 12, 2022 @ 10:08

Have you ever questioned what it would resemble to get Hyderabad Escorts solution from celebs like television actresses, Bollywood starlets, southern Indian starlets, and versions? You should hire Celeb companions for your best buddy. These ladies are from the excellent globe so they likewise wish to produce a solitary world around them by examining with new customers.

They supply Hyderabad Escorts Service secretive but only to some chosen males. These Hyderabad Escort are the excellent suit for you if you enjoy to be a high character and also professional escort. These qualified and cultured companions are so stylish that you wish to suck her up regularly. She has a fervent habits that aids her to obtain rough in bed. These companions like to include journey to their life by being accustomed with a new personality.

Take the best sip of the secret restorative with superstar females


People that are constantly looking for premium Escorts in Hyderabad solutions for friends then these companions are ideal for you. Celebrities take pride in offering an elite solution for their consumers. They are not in the Escort Hyderabad organization simply to get laid by males they are below because they wish to gain an additional income. They additionally enjoy well estimable physic, tall elevations, and also well-groomed behavior along with the wanted perspective that is required for obtaining intermingle well in very high profile societies.

Further, if you are looking for the best buddy for celebrations, nightclubs, malls, markets, and also various other happing areas after that these Escorts Hyderabad are a complete bundle that will offer your needs in the very best possible method. In addition, most model companions are ideal even for in-call solutions where you will get all the conveniences. Many individuals believed that spending quality time with a celeb escort can be challenging to reveal their wishes pleasantly yet this is wrong, they recognize all the internal desires of their clients. Whether, it is dating, romancing, or costs sensual minutes these are the most effective and also comfortable companions.

Make your dream accomplish with friendly nature celebrity escorts
Many individuals assume that these Hyderabad Female Escorts have a high course of mindset so they are not the perfect buddy for their profile however this is the wrong conception. These escorts have a classy perspective but have a friendly manner that you constantly find it simple to express your love, love, and libidos. You can firmly pledgee them for filthy talks, sexual activity, as well as various other behaviors that you desire.

Besides this, you will certainly discover all type of solutions with these celeb escorts. You can share drinks and smoke with these Hyderabad Call girls they will don't bother you as well as supply you the most effective buddy you want. These escorts reveal an easy-going method whether you tell them to strip, play rowdy sex video games, supply blowjobs, as well as trying out wildish sexual moves that you have desired for. So as to get the best solutions for these escorts, one need to always join a trusted Escorts Service Hyderabad firm. At the best firm, you will always discover real as well as reliable escort services that you are constantly searching for to satisfy your desires.

0