Skip to content

TradeWatch Tab Sample

Overview

The TradeWatch Tab Sample plugin adds a new tab to Trade Watch, displaying live statistics and trading actions for the symbol in the active chart. It provides the following key functionalities:

  • Adds the plugin as a new tab in Trade Watch automatically.
  • Displays live trading statistics.
  • Enables market order execution for the current chart symbol.
  • Updates automatically when the active chart symbol changes.

The plugin runs through the dedicated Trade Watch tab, which reflects the active chart. It remains active while cTrader Windows or Mac is running and automatically releases system resources when stopped.

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 the TradeWatch Tab Sample plugin on GitHub, or simply copy it below.

Sample code
using cAlgo.API;

namespace cAlgo.Plugins
{
    [Plugin(AccessRights = AccessRights.None)]
    public class MyTradeWatchTabSample1 : Plugin
    {
        private SymbolStatsControl _symbolStatsControl;
        private TradeControl _tradeControl;

        protected override void OnStart()
        {
            var tab = TradeWatch.AddTab("Active Chart Symbol Stats");

            var panel = new StackPanel
                {Orientation = Orientation.Vertical, HorizontalAlignment = HorizontalAlignment.Center};

            _symbolStatsControl = new SymbolStatsControl {Margin = 10};
            _tradeControl = new TradeControl {Margin = 10};

            panel.AddChild(_symbolStatsControl);
            panel.AddChild(_tradeControl);

            tab.Child = panel;

            SetSymbolStats();

            _tradeControl.Trade += TradeControlOnTrade;
            ChartManager.ActiveFrameChanged += _ => SetSymbolStats();
        }

        private void TradeControlOnTrade(object sender, TradeEventArgs e)
        {
            ExecuteMarketOrder(e.TradeType, e.SymbolName, e.Volume);
        }

        private void SetSymbolStats()
        {
            if (ChartManager.ActiveFrame is not ChartFrame chartFrame)
                return;

            _tradeControl.Symbol = chartFrame.Symbol;
            _symbolStatsControl.Symbol = chartFrame.Symbol;
        }
    }
}

Customisation options

This plugin links the real-time chart context to trade execution through Trade Watch panel. The table below outlines its key components and their functions:

Parameter Description Possible values
TradeWatch.AddTab Tab configuration for the Trade Watch panel. Active chart symbol stats
StackPanel.Orientation Defines the stacking direction of UI elements. Vertical or horizontal
HorizontalAlignment Defines the horizontal alignment of the panel in the tab. Center, left, right, etc.
SymbolStatsControl.Margin Sets margin around the symbol stats control element. 10, 12, 14, etc.
TradeControl.Margin Sets margin around the trade control element. 10, 12, 14, etc.
SymbolStatsControl.Symbol Binds the symbol stats control element to a specific chart symbol. chartframe.symbol, eurusd, gbpjpy, etc.
TradeControl.Symbol Links TradeControl to a symbol for trade actions. chartframe.symbol, eurusd, gbpjpy, etc.
ChartManager.ActiveFrameChanged Event that triggers symbol stat updates when chart frame changes. _ => setsymbolstats()
TradeControl.Trade Event triggered when a trade action is taken from the control panel. tradecontrolontrade or null
ExecuteMarketOrder Executes a trade when called. e.tradetype, e.symbolname, e.volume

Use cases

The TradeWatch Tab Sample plugin provides a straightforward way to enhance cTrader by linking real-time chart context with trade execution. It supports practical applications that streamline trading workflows. Below are practical use cases that demonstrate how the plugin can enhance the trading experience.

Use case Scenario Value
Symbol lock Set the plugin tab to always display a fixed symbol like EURUSD instead of updating with each chart switch. Helps you track and trade one instrument consistently, regardless of chart context.
Chart-linked trading panel Keep the plugin synced with the active chart symbol to always show relevant stats and trading options. Lets you respond quickly to chart analysis without switching tools or panels.
Fixed-volume trade Adjust the default volume in the order handler to a fixed or preferred lot size. Simplifies execution by removing the need to adjust volume each time.
Quick-action terminal Reposition controls horizontally and centre-align for a streamlined trading panel. Enables faster access to both stats and trade buttons in compact setups.

Summary

TradeWatch Tab Sample simplifies trading workflows by combining real-time statistics and trading controls into a dedicated tab within Trade Watch. It updates automatically with the active chart, and its layout, symbol behaviour and trade settings can be customised to suit different trading styles or focus areas.

For further development details, refer to our plugin documentation.