Category Other  Published on 01/07/2019

Curtain

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. There's also a Discord Server now @ https://discord.gg/5GAPMtp

This is the curtain of mistery! Use this tool if you want to backtest something, it will hide every bar after the vertical line so you can scroll the chart freely to take note of support, resistances and other trady thingies.

For any bug report or suggestion contact me by following the group linked above or by commenting below


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 Curtain : Indicator
    {
        private int index, minIndex, thc;
        private bool selected = false;

        protected override void Initialize()
        {
            Thickness();
            Chart.DrawVerticalLine("curtain", Chart.LastVisibleBarIndex - 10, Color.White, 3).IsInteractive = true;
            index = Chart.LastVisibleBarIndex - 10;
            minIndex = index;
            for (int i = index; i <= Chart.BarsTotal; i++)
            {
                Chart.DrawVerticalLine("curtain" + i, i, Color.Black, thc);
            }
            Chart.MouseUp += OnChartMouseUp;
            Chart.ObjectHoverChanged += OnChartObjectHoverChanged;
            Chart.ZoomChanged += OnChartZoomChanged;
        }

        void OnChartZoomChanged(ChartZoomEventArgs obj)
        {
            Thickness();
            for (int i = minIndex; i < index; i++)
            {
                Chart.RemoveObject("curtain" + i);
            }
            minIndex = index;
            for (int i = index; i <= Chart.BarsTotal; i++)
            {
                Chart.DrawVerticalLine("curtain" + i, i, Color.Black, thc);
            }
        }

        void OnChartMouseUp(ChartMouseEventArgs obj)
        {
            if (selected)
            {
                index = (int)obj.BarIndex;
                minIndex = index < minIndex ? index : minIndex;
                for (int i = minIndex; i < index; i++)
                {
                    Chart.RemoveObject("curtain" + i);
                }
                minIndex = index;
                for (int i = index; i <= Chart.BarsTotal; i++)
                {
                    Chart.DrawVerticalLine("curtain" + i, i, Color.Black, thc);
                }
            }
        }

        void OnChartObjectHoverChanged(ChartObjectHoverChangedEventArgs obj)
        {
            if (!obj.IsObjectHovered)
                selected = false;
            else
                try
                {
                    if (obj.ChartObject.Name == "curtain")
                    {
                        selected = true;
                    }
                    else
                        selected = false;

                } catch (Exception e)
                {
                    Print(e);
                    return;
                }
        }

        public override void Calculate(int i)
        {

        }

        private void Thickness()
        {
            if (Chart.Zoom == 0)
            {
                thc = 1;
            }
            if (Chart.Zoom == 1)
            {
                thc = 2;
            }
            if (Chart.Zoom == 2)
            {
                thc = 4;
            }
            if (Chart.Zoom == 3)
            {
                thc = 8;
            }
            if (Chart.Zoom == 4)
            {
                thc = 16;
            }
            if (Chart.Zoom == 5)
            {
                thc = 32;
            }
            return;
        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Curtain.algo
  • Rating: 0
  • Installs: 1422
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
PA
padik · 5 years ago

This is a very useful indicator. Allows easy testing of various strategies.