Chart.MouseMove cannot read Object Properties

Created at 04 Mar 2021, 17:00
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!
bienve.pf's avatar

bienve.pf

Joined 19.09.2018

Chart.MouseMove cannot read Object Properties
04 Mar 2021, 17:00


when moving a TrendLine from Chart.MouseMove the Time1 / Time2 / Y1 / Y2 properties cannot be read either. these properties do not update during drag.

 

 

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MouseDown : Indicator
    {      
        protected override void Initialize()
        {

            ChartTrendLine _line = null;
            double delta = 0.0;

            Chart.MouseMove += arg =>
            {
                if (_line != null)
                {
                    //_line.Time2 = arg.TimeValue;
                    //_line.Y2 = arg.YValue + delta;
                    Chart.DrawStaticText("info", "Time1: " + _line.Time1.ToString() + "/ Y1: " + _line.Y1, VerticalAlignment.Top, HorizontalAlignment.Left, Color.Yellow);
                }
            };

            Chart.MouseDown += arg =>
            {
                Print("MouseDown event....");

                if (_line == null)
                {

                    _line = Chart.DrawTrendLine("myline1", (int)arg.BarIndex, arg.YValue, (int)arg.BarIndex + 10, arg.YValue + delta, Color.Yellow, 2);
                    _line.IsInteractive = true;
                }               
            };
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
        }
    }
}


@bienve.pf
Replies

PanagiotisCharalampous
09 Mar 2021, 10:52

Hi bienve.pf,

I checked this with the product team and the this behavior is normal of interactive objects. A workaround is to create a non-interactive line for drawing purposed and make it interactive on second mouse click. Like this

Chart.MouseDown += arg =>
            {
                Print("MouseDown event....");
                if (_line == null)
                {
                    _line = Chart.DrawTrendLine("myline", arg.TimeValue, arg.YValue, arg.TimeValue, arg.YValue, Color.Yellow, 2);
                    _line.IsInteractive = false;
                }
                else
                {
                    _line.IsInteractive = true;
                    _line = null;
                }
            };

Let me know if this helps.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

bienve.pf
10 Mar 2021, 00:13

RE:

PanagiotisCharalampous said:

Hi bienve.pf,

I checked this with the product team and the this behavior is normal of interactive objects. A workaround is to create a non-interactive line for drawing purposed and make it interactive on second mouse click. Like this

Chart.MouseDown += arg =>
            {
                Print("MouseDown event....");
                if (_line == null)
                {
                    _line = Chart.DrawTrendLine("myline", arg.TimeValue, arg.YValue, arg.TimeValue, arg.YValue, Color.Yellow, 2);
                    _line.IsInteractive = false;
                }
                else
                {
                    _line.IsInteractive = true;
                    _line = null;
                }
            };

Let me know if this helps.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi,
the problem is that if I move the line through one of its vertices it is not possible to capture or read the properties (Time / Y) while moving to be able to dynamically move a text with or other linked lines with it


@bienve.pf

bienve.pf
10 Mar 2021, 00:16

look at the yellow text on left of Chart while moving the line. Data is not updated until object is dropped


@bienve.pf

PanagiotisCharalampous
10 Mar 2021, 08:29

Hi bienve.pf,

Here is the complete cBot code. It seems to work fine for me

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter("Timeframe")]
        public TimeFrame Timeframe { get; set; }

        protected override void OnStart()
        {
            ChartTrendLine _line = null;

            Chart.MouseMove += arg =>
            {
                if (_line != null)
                {
                    _line = Chart.DrawTrendLine("myline", _line.Time1, _line.Y1, arg.TimeValue, arg.YValue, Color.Yellow, 2);
                    Chart.DrawStaticText("info", "Time1: " + _line.Time2.ToString() + "/ Y1: " + _line.Y2, VerticalAlignment.Top, HorizontalAlignment.Left, Color.Yellow);
                }
            };
            Chart.MouseDown += arg =>
            {
                Print("MouseDown event....");
                if (_line == null)
                {
                    _line = Chart.DrawTrendLine("myline", arg.TimeValue, arg.YValue, arg.TimeValue, arg.YValue, Color.Yellow, 2);
                    _line.IsInteractive = false;
                }
                else
                {
                    _line.IsInteractive = true;
                    _line = null;
                }
            };

        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

bienve.pf
10 Mar 2021, 13:46

Thanks for the reply. Good solution


@bienve.pf