Category Volatility  Published on 17/06/2019

Cyclic Lines

Description

Follow my cTrader Telegram group at https://t.me/cTraderCommunity; it's a new community but it will grow fast, plus everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them.

This indicator is the copy of tradingview's 'cyclic lines'.

When started, the indicator will draw two vertical lines, pick them and move them where you want to draw cycles.

The magic number parameter needs to remain constant once the indicator is started to ensure every line will be in order and properly working.

Report any bug in the comments or in the telegram group linked above to have support, enjoy.


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Cycles : Indicator
    {

        [Parameter("Color", DefaultValue = "Blue")]
        public string col { get; set; }
        [Parameter("Transparency %", DefaultValue = 50)]
        public int trsp { get; set; }
        [Parameter("Magic Number", DefaultValue = 0)]
        public int mgc { get; set; }

        private int x1;
        private int x2;

        private string selected = "none";
        private Color alphaColor;
        private string name;

        protected override void Initialize()
        {
            name = " " + mgc.ToString();
            Color color = Color.FromName(col);
            alphaColor = Color.FromArgb((int)(trsp * 2.55), color.R, color.G, color.B);
            drawCursors();
            Chart.ObjectHoverChanged += OnChartObjectHoverChanged;
            Chart.MouseUp += OnChartMouseUp;
        }

        void OnChartMouseUp(ChartMouseEventArgs obj)
        {
            if (selected == "cycle1")
            {
                x1 = (int)obj.BarIndex;
                drawCycles();
            }
            if (selected == "cycle2")
            {
                x2 = (int)obj.BarIndex;
                drawCycles();
            }
        }

        void OnChartObjectHoverChanged(ChartObjectHoverChangedEventArgs obj)
        {
            if (!obj.IsObjectHovered)
                selected = "none";
            else
                try
                {
                    if (obj.ChartObject.Name == "cycle1" + name)
                    {
                        selected = "cycle1";
                    }
                    else if (obj.ChartObject.Name == "cycle2" + name)
                    {
                        selected = "cycle2";
                    }
                    else
                        selected = "none";

                } catch (Exception e)
                {
                    return;
                }
        }

        private void drawCursors()
        {
            int index = Chart.FirstVisibleBarIndex + 10;
            Chart.DrawVerticalLine("cycle1" + name, index, alphaColor, 2);
            Chart.DrawVerticalLine("cycle2" + name, index, alphaColor, 2, LineStyle.DotsRare);
            Chart.FindObject("cycle1" + name).IsInteractive = true;
            Chart.FindObject("cycle2" + name).IsInteractive = true;
            x1 = index;
            x2 = index;
        }

        private void drawCycles()
        {
            for (int i = 0; i < Chart.BarsTotal + 1000; i++)
            {
                Chart.RemoveObject("_cycle" + i + " " + name);
            }
            if (Math.Abs(x2 - x1) > 1)
            {
                int coo1 = Math.Min(x1, x2);
                int coo2 = Math.Max(x1, x2);
                for (int i = 2 * coo2 - coo1; i < Chart.BarsTotal + 1000; i += coo2 - coo1)
                {
                    Chart.DrawVerticalLine("_cycle" + i + " " + name, i, alphaColor);
                    double conjCoord = (Chart.TopY - Chart.BottomY) * 0.75 + Chart.BottomY;
                    Chart.DrawTrendLine("Conj", x1, conjCoord, x2, conjCoord, alphaColor);
                }
            }
        }

        public override void Calculate(int index)
        {

        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

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