Saltar a contenido

Cómo crear plugins de ventana personalizada

Los plugins le permiten crear ventanas personalizadas que contienen sitios web, herramientas o botones que ejecutan operaciones específicas al hacer clic. En este artículo y su video correspondiente, le mostraremos cómo crear ventanas personalizadas que contienen botones de acción usando un plugin.

Crear un plugin

Crearemos una ventana personalizada con un botón que, al hacer clic, establece un take profit para todas las posiciones abiertas. Comenzaremos con los elementos de la ventana y el botón.

Seleccione la aplicación Algo y vaya a la pestaña Plugins. Haga clic en el botón Nuevo. Asegúrese de que la plantilla Blank esté seleccionada. Ingrese un nombre para su plugin, como "Custom Window Plugin", luego haga clic en Create.

Declare el botón y la ventana.

1
2
private Button _buttonAddTakeProfit;
private Window _window;

Inicialice el botón.

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

Inicialice la ventana y agregue el botón como elemento secundario a ella.

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();

Puede copiar el código completo a continuación:

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

Haga clic en el botón Build o use las teclas de acceso rápido Ctrl+B para compilar el plugin. Debería aparecer una ventana personalizada con el botón Add Take Profit.

Puede mover, ocultar, cambiar el tamaño o cerrar la ventana.

Refinar el plugin

Refinaremos el plugin volviendo a nuestro código fuente y agregando un evento que maneja el evento de clic del botón.

1
_buttonAddTakeProfit.Click += _buttonAddTakeProfit_Click;

Agregue la lógica para establecer una opción de take profit a cualquier posición que no la tenga.

 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);
        }
    }
}

Puede copiar el código completo a continuación:

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

Compile el plugin. Vaya a la aplicación Trade, abra algunas posiciones si no tiene ninguna abierta y use el botón Add Take Profit para confirmar que el botón funciona.

Resumen

Creemos que este artículo le ha enseñado cómo crear ventanas personalizadas que contienen botones para operaciones y otros elementos útiles.