Is this a bug?

Created at 22 Jan 2021, 02:46
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!
yomm0401's avatar

yomm0401

Joined 11.04.2020

Is this a bug?
22 Jan 2021, 02:46


 I want to get the Y value when I create a horizontal line on the chart.

I want to take the Y value when I create a horizontal line on the chart. I can get the Y value with the following program, but if there is a position, alert, order line, stoploss takeprofit line on the chart, if I mouse up the horizontal line on that line, I can not get the Y value correctly.

Does anyone know a solution for this?

best regards.


 

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class Yvaluetest : Indicator
    {
        private ChartHorizontalLine Line;
        private double LineYvalue, Defaultprice;
        private bool selected;

        protected override void Initialize()
        {
            Defaultprice = Symbol.Bid - (20 * Symbol.PipSize);
            Line = Chart.DrawHorizontalLine("Line", Defaultprice, Color.Black);
            Line.IsInteractive = true;
            Chart.ObjectHoverChanged += OnChartObjectHoverChanged;
            Chart.MouseUp += OnChartMouseUp;
        }

        public override void Calculate(int index)
        {
        }

        private void OnChartObjectHoverChanged(ChartObjectHoverChangedEventArgs obj)
        {
            if (!obj.IsObjectHovered)
                selected = false;
            else
                try
                {
                    if (obj.ChartObject.Name == "Line")
                    {
                        selected = true;
                    }
                    else
                        selected = false;

                } catch (Exception e)
                {
                    Print(e);
                    return;
                }
        }

        private void OnChartMouseUp(ChartMouseEventArgs obj)
        {
            if (selected)
            {
                LineYvalue = Math.Round(Line.Y, Symbol.Digits);
                Chart.DrawStaticText("Yvalue", LineYvalue.ToString(), VerticalAlignment.Center, HorizontalAlignment.Right, Color.Black);
            }
        }
    }
}

 


@yomm0401