Skip to content

Custom Window Plugin

Overview

Custom Window Plugin creates a simple interface in cTrader for triggering actions based on user input through the following key functionalities:

  • Builds a window interface within the cTrader platform to display a custom visual component alongside the trading workspace.
  • Adds a button for user interaction to initiate actions manually.
  • Triggers predefined logic on button click, enabling consistent handling of trading tasks.
  • Updates open positions based on set conditions, applying changes only when specific criteria are met.

The plugin adds a window where you can perform a specific action on all your open positions. This helps with manual trading by letting you apply the same rule to every position at once, without having to change each one separately.

Plugin creation

Learn how to create plugins, using either C# or Python, in our step-by-step guides.

Custom Window plugin code is available in our public C# and Python repositories. The same code is provided as a template in the algorithm creation wizard in cTrader Windows or Mac, or you can simply copy and use the snippet 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
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
        }
    }        
}
 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
import clr
clr.AddReference("cAlgo.API")

from cAlgo.API import *

class ShowWindowSample():
    def on_start(self):
        addTakeProfitButton = Button()
        addTakeProfitButton.BackgroundColor = Color.SeaGreen
        addTakeProfitButton.Height = 50
        addTakeProfitButton.Text = "Add Take Profit"
        addTakeProfitButton.Click += self.on_add_take_profit_button_click

        window = Window()
        window.Height = 150
        window.Width = 150
        window.Padding = Thickness(5, 10, 10, 5)

        window.Child = addTakeProfitButton;
        window.Show();

    def on_add_take_profit_button_click(self, args):
        for position in api.Positions:
            if position.TakeProfit is None:
                position.ModifyTakeProfitPips(20)

Customisation options

Parameter Description Possible values
_buttonAddTakeProfit.Text Sets the text label displayed on the button. Add take profit
_buttonAddTakeProfit.Height Specifies the height of the button in the window. 50, 60, 65, etc.
_buttonAddTakeProfit.BackgroundColor Sets the background colour of the button. color.seagreen
_buttonAddTakeProfit.Click Triggers an event when the button is clicked. _buttonaddtakeprofit_click
_window.Height Sets the height of the window. 150, 200, 220, etc.
_window.Width Sets the width of the window. 150, 200, 220, etc.
_window.Padding Defines the space inside the window around its child content. (5, 10, 10, 5), (8, 12, 12, 8), etc.
_window.Child Assigns the button as the content inside the window. _buttonaddtakeprofit
position.TakeProfit Checks if a position already has a take profit set. null
position.ModifyTakeProfitPips Modifies the take profit by setting it to a fixed pip value. 20, 24, 26, etc.

Use cases

Use case Scenario Value
Bulk take-profit setter You have multiple open positions without a take profit. Automates the repetitive task of adding a 20-pip take-profit level.
Reactive trade manager The market moves quickly and you need to protect profits instantly. Applies a take profit across positions with one click.
Bulk stop-loss setter You want to quickly apply a 20-pip stop loss across your open positions. Sets consistent risk controls without editing each trade individually.

Summary

Custom Window Plugin enhances manual trading by allowing you to quickly apply a take-profit level of 20 pips to all open positions that do not have one. Through a simple floating interface with a single action button, it brings speed and consistency to trade management.

For further development details, refer to our plugin documentation.