Adding a Label to a Chart.DrawHorizontalLine

Created at 03 Dec 2021, 18:01
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!
MT

MTrade12

Joined 23.11.2021

Adding a Label to a Chart.DrawHorizontalLine
03 Dec 2021, 18:01


Hi Guys, 

Just a quick, and what i imagine to be a simple one!

I want to create a label that's displayed on my chart at the location of my Horizontal Line. 

Here's the code that draws the line:

using System;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Internals;
using System.Linq;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ChartDrawings : Robot
    {

        protected override void OnStart()
        {


        }

        protected override void OnTick()
        {

            var monthly = MarketData.GetBars(TimeFrame.Monthly, Symbol.Name);
            Chart.DrawHorizontalLine("MONTH OPEN", monthly.Last(0).Open, Color.Green, 2, LineStyle.Lines);
            //Chart.DrawText("MONTHLABEL", "MONTHLY OPEN", monthly.Last(0).OpenTime, monthly.Last(0).Close, Color.Purple);

        }
    }
}

As you can see, i've tried to use Chart.DrawText to place the label at the same price as the Horizontal Line, but it doesn't show anywhere. Perhaps the Y axis is wrong?

Thank you for your help and time!

 


@MTrade12
Replies

MTrade12
04 Dec 2021, 04:43

RE:

MTrade12 said:

Hi Guys, 

Just a quick, and what i imagine to be a simple one!

I want to create a label that's displayed on my chart at the location of my Horizontal Line. 

Here's the code that draws the line:

using System;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Internals;
using System.Linq;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ChartDrawings : Robot
    {

        protected override void OnStart()
        {


        }

        protected override void OnTick()
        {

            var monthly = MarketData.GetBars(TimeFrame.Monthly, Symbol.Name);
            Chart.DrawHorizontalLine("MONTH OPEN", monthly.Last(0).Open, Color.Green, 2, LineStyle.Lines);
            //Chart.DrawText("MONTHLABEL", "MONTHLY OPEN", monthly.Last(0).OpenTime, monthly.Last(0).Close, Color.Purple);

        }
    }
}

As you can see, i've tried to use Chart.DrawText to place the label at the same price as the Horizontal Line, but it doesn't show anywhere. Perhaps the Y axis is wrong?

Thank you for your help and time!

 

Hey Guys, 

I figured it out! :-)

Here's the code i used in case anyone wants the same thing in the future:

 

            var monthly = MarketData.GetBars(TimeFrame.Monthly, Symbol.Name);

            DateTime today = System.DateTime.Now;
            TimeSpan duration = new System.TimeSpan(0, 0, 10, 0);
            DateTime answer = openTime.Add(duration);

            Chart.DrawText("MONTHLABEL", "MONTHLY OPEN", answer, monthly.Last(0).Open, Color.Purple);

 


@MTrade12