コンテンツにスキップ

カスタムウィンドウプラグインの作成方法

プラグインを使用すると、ウェブサイト、ツール、またはクリック時に特定の操作を実行するボタンを含むカスタムウィンドウを作成できます。 この記事と対応するビデオでは、プラグインを使用してアクションボタンを含むカスタムウィンドウを作成する方法を紹介します。

プラグインを作成する

すべてのオープンポジションに利食いを設定するボタンを含むカスタムウィンドウを作成します。 ウィンドウとボタンの要素から始めます。

Algo アプリを選択し、プラグイン タブに移動します。 新規ボタンをクリックします。 空白 テンプレートが選択されていることを確認します。 「Custom Window Plugin」などのプラグイン名を入力し、作成 をクリックします。

ボタンとウィンドウを宣言します。

1
2
private Button _buttonAddTakeProfit;
private Window _window;

ボタンを初期化します。

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

ウィンドウを初期化し、ボタンを子要素として追加します。

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

以下の完全なコードをコピーできます:

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

ビルド ボタンをクリックするか、Ctrl+B ホットキーを使用してプラグインをビルドします。 利食いを追加 ボタンを含むカスタムウィンドウが表示されます。

ウィンドウを移動、非表示、サイズ変更、または閉じることができます。

プラグインを改良する

ソースコードに戻り、ボタンクリックイベントを処理するイベントを追加してプラグインを改良します。

1
_buttonAddTakeProfit.Click += _buttonAddTakeProfit_Click;

利食いオプションが設定されていないポジションに利食いを設定するロジックを追加します。

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

以下の完全なコードをコピーできます:

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

プラグインをビルドします。 Trade アプリに移動し、オープンポジションがない場合はいくつか開き、利食いを追加 ボタンを使用してボタンが機能することを確認します。

概要

この記事では、操作やその他の便利な要素を含むカスタムウィンドウを作成する方法を学んだと思います。