Help : stick vertical line (while change timeframe won't to the end of chart)

Created at 24 Jun 2021, 19:19
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
IR

IRCtrader

Joined 17.06.2021

Help : stick vertical line (while change timeframe won't to the end of chart)
24 Jun 2021, 19:19


Please help me to complete this useful indicator.

this indicator has a button that create a vertical line to chart. when change the time frame, chart won't fo to the end.

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 Vline : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        ChartVerticalLine vl;

        DateTime date;


        protected override void Initialize()
        {

            var toggleButton = new ToggleButton 
            {
                Text = "Stick Line",
                Margin = 10,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Left,
                MaxWidth = 100,
                MaxHeight = 40

            };
            toggleButton.Checked += ToggleButton_Checked;
            toggleButton.Unchecked += ToggleButton_Unchecked;

            Chart.AddControl(toggleButton);

            Chart.ScrollChanged += OnChartScrollChanged;

            Chart.ObjectsUpdated += OnChartObjectsUpdated;
            Chart.ScrollXTo(vl.Time);

        }

        public override void Calculate(int index)
        {

        }

        private void Button_Click(ButtonClickEventArgs obj)
        {
            var vl = Chart.DrawVerticalLine("vertical_line", Chart.LastVisibleBarIndex, Color.Red, 2, LineStyle.DotsRare);
            vl.IsInteractive = true;

            Print(date.ToShortTimeString());


        }
        protected void ToggleButton_Checked(ToggleButtonEventArgs obj)
        {
            vl = Chart.DrawVerticalLine("vertical_line", Chart.LastVisibleBarIndex, Color.Red, 2, LineStyle.DotsRare);
            vl.IsInteractive = true;
            vl.IsHidden = false;
            Print(vl.Time.ToShortTimeString());
            var date = new DateTime(vl.Time.Year, vl.Time.Month, vl.Time.Day, vl.Time.Hour, vl.Time.Minute, vl.Time.Second);

        }
        private void ToggleButton_Unchecked(ToggleButtonEventArgs obj)
        {



            Chart.RemoveObject(vl.Name);
        }

        void OnChartScrollChanged(ChartScrollEventArgs obj)
        {
            Chart.ScrollXTo(vl.Time);

        }
        void OnChartObjectsUpdated(ChartObjectsUpdatedEventArgs obj)
        {
            date = vl.Time;
        }


    }
}

 


@IRCtrader