Drawing a horizontal line on the main chart

Created at 21 Mar 2020, 03:14
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!
FS

fsenna68

Joined 21.03.2020

Drawing a horizontal line on the main chart
21 Mar 2020, 03:14


Drawing a horizontal line on a chart

I'm using the below code to draw lines on the chart. The code has no pointed errors, but instead of plotting the lines on the main chart, it plots below the chart on a new chart area. How can I create this lines on the main chart ? I've tried most of the codes in the forum and still didn't work for me:

[Parameter(DefaultValue = 100)]
        public int StepPips { get; set; }

        [Parameter("Cor da linhas", DefaultValue = "White")]
        public string corLinha { get; set; }

        protected override void Initialize()
        {
            double max = Bars.HighPrices.Maximum(Bars.HighPrices.Count);
            double min = Bars.LowPrices.Minimum(Bars.LowPrices.Count);

            double step = Symbol.PipSize * StepPips;
            double start = Math.Floor(min / step) * step;

            Color colorLine = GetColor();
            //ChartArea chrLine = null;
            for (double level = start; level <= max + step; level += step)
            {

                Chart.DrawHorizontalLine("line_" + level, level, colorLine, 1, LineStyle.LinesDots);
            }


        }

 

Thanks for help


@fsenna68
Replies

firemyst
21 Mar 2020, 15:04

You haven't said if "IsOverlay=false" or not

You haven't shown us with your code if this indicator is "IsOverlay" or not.

In a test indicator I have where "IsOverlay = false", the following both work as expected:

 

//This is on AUS200, hence 4800 level for main chart

Chart.DrawHorizontalLine("testline", 4800.0, Color.Red); //draws on main chart
IndicatorArea.DrawHorizontalLine("testline2", 0, Color.Red); //draws in indicator area

 


@firemyst