identify that the user place a ChartTrendLine on the chart

Created at 22 Jul 2021, 09:06
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!
EY

eynt

Joined 08.05.2020

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


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

 

Thanks


@eynt
Replies

amusleh
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)
        {
        }
    }
}

 


@amusleh