Adding both Control and Drawing to Chart

Created at 03 Sep 2023, 17:20
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!
MA

matcwhite

Joined 03.09.2023

Adding both Control and Drawing to Chart
03 Sep 2023, 17:20


Hello,

I'm working on an indicator which adds drawings (rectangles, lines etc.) and also controls related to the drawings. However I seem to be unable to display both on the chart simultaneously. If I add the control to the chart followed by the drawing, only the drawing appears. if I remove the drawing, the control appears. I've reproduced the issue in this simple indicator code:

using cAlgo.API;

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None)]
    public class AddControltest : Indicator
    {
		private bool _mouseDown = false;
		private bool _added = false;
		private TextBox _tb;

        protected override void Initialize()
        {
			Chart.MouseUp += OnChartMouseUp;
			Chart.MouseDown += OnChartMouseDown;

			_tb = new TextBox {
				Text = "Test",
				Margin = 0,
				Height = 20,
				IsVisible = true,
			};
		}

		public override void Calculate(int index) { }

		private void OnChartMouseDown(ChartMouseEventArgs args) {
			_mouseDown = true;

			System.Threading.Timer timer = null;
			timer = new System.Threading.Timer((obj) => {
				_mouseDown = false;
				timer.Dispose();
			}, null, 200, System.Threading.Timeout.Infinite);
		}

		private void OnChartMouseUp(ChartMouseEventArgs args) {
			if (!_mouseDown) return;

			if (!_added) {
				Chart.AddControl(_tb, args.TimeValue, args.YValue);
				Chart.DrawVerticalLine("vline", args.TimeValue, Color.White);
				_added = true;
			} else {
				Chart.MoveControl(_tb, args.TimeValue, args.YValue);
				Chart.DrawVerticalLine("vline", args.TimeValue, Color.White);
			}
		}
	}
}

When running this indicator, clicking anywhere in the chart should add a “Test” TextBox at the Time/Price coordinates along with a vertical line at the same Time. However, only the vertical line appears. If I remove the Chart.DrawVerticalLine lines in the code then the TextBox appears.

What's going on? Is there some clash between Controls and Drawings?

Hope someone can help!

Thanks,

Mat


@matcwhite
Replies

PanagiotisChar
04 Sep 2023, 05:31 ( Updated at: 21 Dec 2023, 09:23 )

Hi there,

Which version do you use? Seems to work fine on the latest one


@PanagiotisChar

matcwhite
04 Sep 2023, 08:19 ( Updated at: 04 Sep 2023, 13:14 )

RE: Adding both Control and Drawing to Chart

PanagiotisChar said: 

Hi there,

Which version do you use? Seems to work fine on the latest one 

Version 4.8.19. I assumed it was the latest version because I can't see any option to upgrade it. It this I something I have to contact my broker about?

Edit: I'm using the broker-branded cTrader I downloaded from my broker. Should I switch to the official cTrader version or what? I can't see how to upgrade otherwise.

Thanks,

Mat

 


@matcwhite

matcwhite
04 Sep 2023, 19:14 ( Updated at: 04 Sep 2023, 19:16 )

RE: Adding both Control and Drawing to Chart

[deleted]


@matcwhite

matcwhite
04 Sep 2023, 19:15 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE: Adding both Control and Drawing to Chart

matcwhite said: 

PanagiotisChar said: 

Hi there,

Which version do you use? Seems to work fine on the latest one 

Version 4.8.19. I assumed it was the latest version because I can't see any option to upgrade it. It this I something I have to contact my broker about?

Edit: I'm using the broker-branded cTrader I downloaded from my broker. Should I switch to the official cTrader version or what? I can't see how to upgrade otherwise.

Thanks,

Mat

 

Right, I'm still having issues….

I've downloaded and installed the latest version of cTrader directly from Spotware, I now have version 4.8.25.

The indicator "seems to only work on first run", to reproduce:

  1. Launch cTrader
  2. Go to Automate, then the indicators tab
  3. Add a symbol to the indicator to test it.
  4. Indicator works as expected
  5. Remove the symbol.
  6. Re-add the symbol.
  7. Indicator now only shows the vertical lines and not the control.

screenshot:

Incidentally, I'm also seeing these popups occasionally, started getting them when playing with controls:

Any ideas?

 

Thanks,

Mat

 

 

 


@matcwhite

matcwhite
05 Sep 2023, 08:16

RE: RE: RE: Adding both Control and Drawing to Chart

matcwhite said: 

matcwhite said: 

PanagiotisChar said: 

Hi there,

Which version do you use? Seems to work fine on the latest one 

Version 4.8.19. I assumed it was the latest version because I can't see any option to upgrade it. It this I something I have to contact my broker about?

Edit: I'm using the broker-branded cTrader I downloaded from my broker. Should I switch to the official cTrader version or what? I can't see how to upgrade otherwise.

Thanks,

Mat

 

Right, I'm still having issues….

I've downloaded and installed the latest version of cTrader directly from Spotware, I now have version 4.8.25.

The indicator "seems to only work on first run", to reproduce:

  1. Launch cTrader
  2. Go to Automate, then the indicators tab
  3. Add a symbol to the indicator to test it.
  4. Indicator works as expected
  5. Remove the symbol.
  6. Re-add the symbol.
  7. Indicator now only shows the vertical lines and not the control.

screenshot:

 

Incidentally, I'm also seeing these popups occasionally, started getting them when playing with controls:

 

Any ideas?

 

Thanks,

Mat

 

I have just tried a clean reinstall of both cTrader and Visual Studio and the problem is still there, and still getting those pop up error messages.

Thanks,

Mat

 

 


@matcwhite