How to get the horizontalLine's Y value?

Created at 09 May 2023, 21:21
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!
96

963168364

Joined 19.03.2023

How to get the horizontalLine's Y value?
09 May 2023, 21:21


I want to get the Y value when i put a  horizontalLine on a chart manually.

I tried the following things in the indicator:

        protected override void Initialize()
        {
            Chart.ObjectsAdded += Chart_ObjectsAdded;
        }

        private void Chart_ObjectsAdded(ChartObjectsAddedEventArgs obj)
        {
             Print("{0} objects added to chart", obj.ChartObjects.Count);
             var objtype = obj.ChartObjects.GetType();
             var newobj= obj.ChartObjects;
             Print(newobj.Last().Name);           // horizontalLine number
             Print(newobj.Last().ToString());     // cTrader.Automate.Adapters.ChartApi.ChartObjects.ChartHorizontalLineAdapter
             Print(newobj.Last().Comment);
             Print(newobj.Last().GetType());    // cTrader.Automate.Adapters.ChartApi.ChartObjects.ChartHorizontalLineAdapter
       }

 

Then, i get the correct name and Comment(nothing),but can't get the Y value.

How to access the chart objects's value  like lines(horizontalLine's Y, vertical line's datetime) or rectangle(time and Y)?

 

Need help, thanks.

 

 

 

 

 

 

 

 


@963168364
Replies

PanagiotisChar
10 May 2023, 08:29

Hi there,

Here you go

        protected override void Initialize()
        {
            Chart.ObjectsAdded += Chart_ObjectsAdded;
        }
            
        private void Chart_ObjectsAdded(ChartObjectsAddedEventArgs obj)
        {
            if (obj.ChartObjects[0] is ChartHorizontalLine)
            {
                Print((obj.ChartObjects[0] as ChartHorizontalLine).Y);
            }
       }

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

963168364
12 May 2023, 02:37

RE: Thank you so much! It works fine!

PanagiotisChar said:

Hi there,

Here you go

        protected override void Initialize()
        {
            Chart.ObjectsAdded += Chart_ObjectsAdded;
        }
            
        private void Chart_ObjectsAdded(ChartObjectsAddedEventArgs obj)
        {
            if (obj.ChartObjects[0] is ChartHorizontalLine)
            {
                Print((obj.ChartObjects[0] as ChartHorizontalLine).Y);
            }
       }

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 


@963168364