identify that the user place a ChartTrendLine on the chart

yuval.ein since: 08 May 2020;

  22 Jul 2021, 09:06
identify that the user place a ChartTrendLine on the chart

Is there an event or any other way to identify that the user place a ChartTrendLine on the chart?

Thanks

amusleh's avatar

amusleh since: 01 Mar 2021;

  22 Jul 2021, 10:09

Hi,

Yes, you can use the Chart.ObjectAdded event and then check the type of added object if it's a trend line or not.

using cAlgo.API;
using System.Linq;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Indicator
    {
        protected override void Initialize()
        {
            Chart.ObjectsAdded += Chart_ObjectsAdded;
        }

        private void Chart_ObjectsAdded(ChartObjectsAddedEventArgs obj)
        {
            if (obj.ChartObjects.All(chartObject => chartObject.ObjectType == ChartObjectType.TrendLine))
            {
                // If all of the new added objects were trend line the code here will be executed
            }
        }

        public override void Calculate(int index)
        {
        }
    }
}
Community Developer | Spotware | Telegram: @algodeveloper