A button on a chart

Created at 04 Aug 2020, 16:39
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!
CR

crou

Joined 01.04.2019

A button on a chart
04 Aug 2020, 16:39


Hi,

 

what should I do to see a button on a chart?

I wrote this and it doesn't appear:

 

  public override void Calculate(int index)
        {
            Button button1 = new Button();

            button1.BackgroundColor = Color.White;
            button1.Text = "Button";
            button1.Top = 100;
            button1.Left = 100;
            button1.IsVisible = true;
        }

 

Thank you.


@crou
Replies

PanagiotisCharalampous
04 Aug 2020, 16:41

Hi crou,

You can check the Sample Trading Panel sample cBot that comes with the platform. It has examples of adding buttons to the charts.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

crou
04 Aug 2020, 16:43

Ok, I know

Okay. I didn't add control, by:

 

Chart.AddControl(button1);

 

No question.


@crou

crou
04 Aug 2020, 16:51

Thank you for your fast response.

I wasn't aware of the sample bot you mentioned.


@crou

crou
04 Aug 2020, 18:13

I have a silly question.

 

I would like the button to disappear after it is clicked. I wrote a separate method, but it doesn't recognize the button inside of it.

How should I do it?

 

public override void Calculate(int index)
        {
            Button button1 = new Button();

            button1.BackgroundColor = Color.White;
            button1.Text = "Button";
            button1.Top = 100;
            button1.Left = 100;
            button1.IsVisible = true;
            button1.IsEnabled = true;

            Chart.AddControl(button1);

            button1.Click += args => CloseButton();
        }

        private void CloseButton()
        {
            button1.IsEnabled = false;
            button1.IsVisible = false;
        }

Thank you.


@crou

crou
04 Aug 2020, 18:24

Ok, I know

Okay, I know again.

 

private void CloseAlert(object sender)
        {
            Button button1 = sender as Button;

//...
        }

 


@crou

crou
06 Sep 2020, 15:10

Is it possible to add a button to an oscillators area?


@crou

PanagiotisCharalampous
07 Sep 2020, 08:27

Hi crou,

Yes it is. See below

Chart.IndicatorAreas[0].AddControl(button1);

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

crou
07 Sep 2020, 15:44

Thank you.


@crou