button declaration
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.
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