This example code will add a new button to the cTrader toolbar, and when pressed, it will open a window—additional changes are required for a fully functional tool.
Download ⬇️
using System;
using cAlgo.API;
namespace cAlgo.Plugins
{
[Plugin(AccessRights = AccessRights.None)]
public class ToolbarButtonWithWindow : Plugin
{
private Window _customWindow;
protected override void OnStart()
{
var icon = new SvgIcon(@"
<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' viewBox='0 0 24 24'>
<path stroke='#BFBFBF' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M12 5v14m-7-7h14'/>
</svg>");
var command = Commands.Add(CommandType.ChartContainerToolbar, OnToolbarButtonClicked, icon);
command.ToolTip = "Open Custom Window";
}
private void OnToolbarButtonClicked(CommandArgs args)
{
if (_customWindow != null)
return;
var button = new Button
{
Text = "Click Me",
Margin = 10,
BackgroundColor = Color.SeaGreen
};
button.Click += (ButtonClickEventArgs _) => MessageBox.Show("Button Clicked!", "Info");
_customWindow = new Window
{
Title = "My Custom Window",
Width = 300,
Height = 200,
Padding = new Thickness(10)
};
_customWindow.Child = button;
_customWindow.Closed += (WindowClosedEventArgs e) => { _customWindow = null; };
_customWindow.Show();
}
protected override void OnStop()
{
_customWindow?.Close();
}
}
}
/*
This cTrader cBot was created with clear instructions using a highly knowledgeable Ai assistant for cTrader's Algo platform.
It helps users write, debug, and optimize C# trading bots and provides clear and accurate cTrader API documentation when requested.
No coding experience is required.
Website: https://clickalgo.com/code-ai
*/