button declaration

Created at 31 Mar 2020, 16:45
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!
TJ

Tj11

Joined 24.10.2019

button declaration
31 Mar 2020, 16:45


Dear Panagiotis,

Could you please advise how to declare the button properly.

.

Declaring button like this results in crash.

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 button : Indicator
    {
        public Button hide;
        public bool hideSetInfo = false;

        [Parameter(DefaultValue = "strategy")]
        public string Strategy { get; set; }


        protected override void Initialize()
        {
            //function
            function();

            //button
            hide.Click += onHideClick;
        }

        public override void Calculate(int index)
        {
        }


        void onHideClick(ButtonClickEventArgs obj)
        {
            hideSetInfo = !hideSetInfo;
        }


        public void function()
        {
            if (Strategy != "")
            {
                hide.HorizontalAlignment = HorizontalAlignment.Left;
                hide.VerticalAlignment = VerticalAlignment.Top;
                hide.Text = Strategy;
                hide.Height = 100;
                hide.Width = 100;
                hide.BackgroundColor = Color.Black;
                hide.ForegroundColor = Color.Black;
                hide.IsEnabled = true;
                hide.IsVisible = true;
            }
        }
    }
}

.

result : Crashed in Initialize with NullReferenceException: Object reference not set to an instance of an object.

 


@Tj11
Replies

PanagiotisCharalampous
31 Mar 2020, 16:57

Hi Tj11,

Check here. You are actually missing an object initializer. 

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous