Accessing chart objects

Created at 07 Mar 2017, 11:44
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!
AL

alga

Joined 07.03.2017

Accessing chart objects
07 Mar 2017, 11:44


I would need to find a manually drawn line by name by its comment. Is this currently possible?

 


@alga
Replies

ctrader.guru
09 Feb 2024, 06:00

Try this approach
using cAlgo.API;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class MyRobot : Robot
    {
        protected override void OnStart()
        {

            ChartTrendLine desiredLine = null;

            foreach (ChartObject line in Chart.Objects)
            {
                if (line.ObjectType == ChartObjectType.TrendLine && line.Comment == "Your Comment")
                {
                    desiredLine = (ChartTrendLine)line;
                    break;
                }
            }

            // Access the desired line
            if (desiredLine != null)
            {
                // Do something with the desired line
                Print("Desired line value: " + desiredLine.Name);
            }
            else
            {
                Print("No line with the specified comment found.");
            }
        }
    }
}

@ctrader.guru