AW Vline free

by khoshroomahdi in category Other at 25/06/2021
Description

don't move to the end of chart after timeframe changing.

it should be better to use for near history. for long history this have delay.

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 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 AWVLine : Indicator
    {

        ChartVerticalLine vl;


        [Parameter("Horizental Alignment", DefaultValue = HorizontalAlignment.Left, Group = "Button")]
        public HorizontalAlignment HAlignment { get; set; }
        [Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Top, Group = "Button")]
        public VerticalAlignment VAlignment { get; set; }
        [Parameter("Backgroun Color", DefaultValue = "", Group = "Button")]
        public string Colorb { get; set; }
        [Parameter("Foreground Color", DefaultValue = "Black", Group = "Button")]
        public string Colorf { get; set; }
        [Parameter("Opacity", DefaultValue = 0.7, MinValue = 0.1, MaxValue = 1, Group = "Button")]
        public double Opacity { get; set; }
        [Parameter("Line Color", DefaultValue = "Red", Group = "Line")]
        public string LineColor { get; set; }
        [Parameter("LineStyle", DefaultValue = LineStyle.LinesDots, Group = "Line")]
        public LineStyle ls { get; set; }
        [Parameter("Thickness", DefaultValue = 2, Group = "Line")]
        public int Thickness { get; set; }


        protected override void Initialize()
        {

            var toggleButton = new ToggleButton 
            {
                Text = "Vline",
                Margin = 10,
                VerticalAlignment = VAlignment,
                HorizontalAlignment = HAlignment,
                MaxWidth = 70,
                MaxHeight = 40,
                BackgroundColor = Colorb,
                Opacity = Opacity,
                ForegroundColor = Colorf,
                BorderThickness = 1,
                BorderColor = Colorf

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

            Chart.AddControl(toggleButton);

            foreach (ChartObject obj in Chart.Objects)
            {
                if (obj.ObjectType == ChartObjectType.VerticalLine)
                {
                    ChartVerticalLine line = (ChartVerticalLine)obj;
                    if (line.Name == "scrollLine")
                    {
                        Bars bars = MarketData.GetBars(Chart.TimeFrame, SymbolName);
                        int ind = bars.OpenTimes.GetIndexByTime(line.Time);
                        Chart.ScrollXTo(ind - 20);
                    }
                }
            }

        }

        public override void Calculate(int index)
        {
        }


        protected void ToggleButton_Checked(ToggleButtonEventArgs obj)
        {
            vl = Chart.DrawVerticalLine("scrollLine", (Chart.LastVisibleBarIndex + Chart.FirstVisibleBarIndex) / 2, Color.FromName(LineColor), Thickness, ls);
            vl.IsInteractive = true;

        }

        private void ToggleButton_Unchecked(ToggleButtonEventArgs obj)
        {
            Chart.RemoveObject(vl.Name);
        }

    }
}
Comments
0