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, edit and build plugins from a template or from scratch in our step-by-step guide.

You can find the code of Custom Window Plugin on GitHub, or simply copy it below.

Sample code
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
        }
    }        
}

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.