Skip to content

How to create custom window plugins

Plugins allow you to create custom windows containing websites, tools or buttons that execute specific operations when clicked. In this article and its corresponding video, we will show you how to create custom windows containing action buttons using a plugin.

Create a plugin

We will create a custom window with a button that, when clicked, sets a take profit for all open positions. We will start with the window and button elements.

Select the Algo app and go to the Plugins tab. Click the New button. Ensure the Blank template is selected. Enter a name for your plugin, such as "Custom Window Plugin", then click Create.

Declare the button and the window.

1
2
private Button _buttonAddTakeProfit;
private Window _window;

Initialise the button.

1
2
3
4
5
6
_buttonAddTakeProfit = new Button
{
    BackgroundColor = Color.SeaGreen,
    Height = 50,
    Text = "Add Take Profit"
};

Initialise the window and add the button as a child to it.

1
2
3
4
5
6
7
8
9
_window = new Window
{
    Height = 150,
    Width = 150,
    Padding = new Thickness(5, 10, 10, 5)
};

_window.Child = _buttonAddTakeProfit;
_window.Show();

You can copy the full code below:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Plugins
{
    [Plugin(AccessRights = AccessRights.None)]
    public class CustomWindowPlugin : Plugin

    {

        private Button _buttonAddTakeProfit;
        private Window _window;

        protected override void OnStart()
        {

            _buttonAddTakeProfit = new Button
            {
                BackgroundColor = Color.SeaGreen,
                Height = 50,
                Text = "Add Take Profit"
            };

            _window = new Window
            {
                Height = 150,
                Width = 150,
                Padding = new Thickness(5, 10, 10, 5)
            };

            _window.Child = _buttonAddTakeProfit;
            _window.Show();

        }

        protected override void OnStop()
        {
            // Handle Plugin stop here
        }
    }        
}

Click the Build button or use the Ctrl+B hotkeys to build the plugin. A custom window with the Add Take Profit button should appear.

You can move, hide, resize or close the window.

Refine the plugin

We will refine the plugin by returning to our source code and adding an event that handles the button-click event.

1
_buttonAddTakeProfit.Click += _buttonAddTakeProfit_Click;

Add the logic for setting a take-profit option to any position that lacks it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
private void _buttonAddTakeProfit_Click(ButtonClickEventArgs args)
{
    foreach (var position in Positions)
    {
        if (position.TakeProfit is null)
        {
            position.ModifyTakeProfitPips(20);
        }
    }
}

You can copy the full code below:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Plugins
{
    [Plugin(AccessRights = AccessRights.None)]
    public class CustomWindowPlugin : Plugin

    {
        private Button _buttonAddTakeProfit;
        private Window _window;

        protected override void OnStart()
        {
            _buttonAddTakeProfit = new Button
            {
                BackgroundColor = Color.SeaGreen,
                Height = 50,
                Text = "Add Take Profit"
            };

            _buttonAddTakeProfit.Click += _buttonAddTakeProfit_Click;

            _window = new Window
            {
                Height = 150,
                Width = 150,
                Padding = new Thickness(5, 10, 10, 5)
            };

            _window.Child = _buttonAddTakeProfit;
            _window.Show();
        }

        private void _buttonAddTakeProfit_Click(ButtonClickEventArgs args)
        {
            foreach (var position in Positions)
            {
                if (position.TakeProfit is null)
                {
                    position.ModifyTakeProfitPips(20);
                }
            }
        }        

        protected override void OnStop()
        {
            // Handle Plugin stop here
        }
    }        
}

Build the plugin. Go to the Trade app, open some positions if you have none open and use the Add Take Profit button to confirm that the button works.

Summary

We believe this article has taught you how to create custom windows containing buttons for operations and other useful elements.

Subscribe to our YouTube channel