ChartObjectsUpdatedEventArgs How can I get Y value from a Horizental Line?

Created at 06 May 2022, 18:57
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!
Capt.Z-Fort.Builder's avatar

Capt.Z-Fort.Builder

Joined 03.06.2020

ChartObjectsUpdatedEventArgs How can I get Y value from a Horizental Line?
06 May 2022, 18:57


Hello,

I use the below event to detect if a HorizentalLine has been modified. And the code can easily get horizentalLine's name, but how can I get the Y value of the modified horizentalLine?

The code below,  horizentalLine.Y.ToString("0.0") report error.

Thanks, if any advice.

        private void Chart_ObjectsModified(ChartObjectsUpdatedEventArgs obj)
        {
            var horizentalLine = obj.ChartObjects.FirstOrDefault(iObject => iObject.ObjectType == ChartObjectType.HorizontalLine);
            if (horizentalLine != null) 
            {
                Print("Found object with name {0}, Y-Value: {1}", horizentalLine.Name, horizentalLine.Y.ToString("0.0");
            }
        }

 


@Capt.Z-Fort.Builder
Replies

Capt.Z-Fort.Builder
08 May 2022, 00:55

RE:

I have resolved this problem by bringing another method to return the Y-value.

        private double HLineYValue(string s_HLineNm) //Return HorizentalLine's Y-Value by HorizentalLine'sName
        {
            var hLines = Chart.FindAllObjects(ChartObjectType.HorizontalLine);
            foreach (ChartHorizontalLine hline in hLines) { if (hline.Name == s_HLineNm) { return hline.Y; } } 
            return 0;
        }

TheNiatpac said:

Hello,

I use the below event to detect if a HorizentalLine has been modified. And the code can easily get horizentalLine's name, but how can I get the Y value of the modified horizentalLine?

The code below,  horizentalLine.Y.ToString("0.0") report error.

Thanks, if any advice.

        private void Chart_ObjectsModified(ChartObjectsUpdatedEventArgs obj)
        {
            var horizentalLine = obj.ChartObjects.FirstOrDefault(iObject => iObject.ObjectType == ChartObjectType.HorizontalLine);
            if (horizentalLine != null) 
            {
                Print("Found object with name {0}, Y-Value: {1}", horizentalLine.Name, horizentalLine.Y.ToString("0.0");
            }
        }

 

 


@Capt.Z-Fort.Builder