アクティブ通貨ペアパネル用のプラグインを作成する方法 VIDEO
プラグインを使用すると、アクティブ通貨ペアパネル (ASP) にウェブサイトページやその他のWebViewコンポーネント、計算機、分析やデータボード、AIツールなどを含む新しいセクションを簡単に作成できます。
この記事と対応するビデオでは、プラグインを使用してアクティブ通貨ペアパネルに新しいセクションを追加する方法を紹介します。
プラグインを作成する WebViewセクションを作成する Algo アプリに移動し、プラグイン タブに移動します。 新規 ボタンをクリックして新しいプラグインを作成します。 リストから オプションを選択し、ASP Section Example を選択します。 「My ASP Example」などのプラグイン名を付けます。
作成 ボタンをクリックします。
コードエディタが表示されたら、コードの「My title」部分をプラグインに付けた名前に置き換えます。
var block = Asp . SymbolTab . AddBlock ( "My ASP Example" );
以下の完全なコードをコピーできます:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 using cAlgo.API ;
namespace cAlgo.Plugins
{
[Plugin(AccessRights = AccessRights.None)]
public class MyASPExample : Plugin
{
protected override void OnStart ()
{
var block = Asp . SymbolTab . AddBlock ( "My ASP Example" );
block . Index = 2 ;
block . Height = 500 ;
block . IsExpanded = true ;
var webView = new WebView ();
block . Child = webView ;
webView . NavigateAsync ( "https://ctrader.com/" );
}
}
}
ビルド ボタンをクリックするか、Ctrl + B を押してプラグインをビルドします。
Trade アプリに再度移動し、アクティブ通貨ペアパネル にプラグインが表示している内容を確認します。 この場合、cTraderフォーラムを表示するWebViewコンポーネントが表示されます。
VWAPボックスを作成する この例では、WebViewを現在のオープンポジションの売買高加重平均価格(VWAP)を表示するボックスに置き換えます。
プラグインコードに戻り、WebViewセクションを削除します。
ブロックの高さを100に設定します。
関連情報を表示する2つのテキストブロックを定義します。
TextBlock _txtBuyVWAP ;
TextBlock _txtSellVWAP ;
テキストボックスのパネルを追加します。
var panel = new StackPanel
{
Orientation = Orientation . Vertical
};
2つのテキストブロックを初期化します。
_txtBuyVWAP = new TextBlock
{
Text = "Buy Text Box"
};
_txtSellVWAP = new TextBlock
{
Text = "Sell Text Box"
};
テキストボックスをパネルに追加し、パネルをプラグインブロックの子コントロールにします。
panel . AddChild ( _txtBuyVWAP );
panel . AddChild ( _txtSellVWAP );
block . Child = panel ;
以下の完全なコードをコピーできます:
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 using cAlgo.API ;
namespace cAlgo.Plugins
{
[Plugin(AccessRights = AccessRights.None)]
public class MyASPExample : Plugin
{
TextBlock _txtBuyVWAP ;
TextBlock _txtSellVWAP ;
protected override void OnStart ()
{
var block = Asp . SymbolTab . AddBlock ( "ASP Section Example" );
block . Index = 2 ;
block . Height = 100 ;
block . IsExpanded = true ;
var panel = new StackPanel
{
Orientation = Orientation . Vertical
};
_txtBuyVWAP = new TextBlock
{
Text = "Buy Text Box"
};
_txtSellVWAP = new TextBlock
{
Text = "Sell Text Box"
};
panel . AddChild ( _txtBuyVWAP );
panel . AddChild ( _txtSellVWAP );
block . Child = panel ;
}
}
}
プラグインをビルドし、Trade アプリに移動します。
WebViewコンポーネントの代わりに2つのテキストボックスが表示されるはずです。
プラグインを改良する プラグインにロジックを追加する プラグインコードに移動し、以下の名前空間を追加します:
using System ;
using System.Linq ;
買いと売りの方向のVWAPを計算するロジックを実装します。
var buyPositions = Positions . Where ( p => p . TradeType == TradeType . Buy );
_txtBuyVWAP . Text = "Buy Positions VWAF: " + Math . Round (( buyPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / buyPositions . Sum ( p => p . VolumeInUnits )), 5 );
var sellPositions = Positions . Where ( p => p . TradeType == TradeType . Sell );
_txtSellVWAP . Text = "Sell Positions VWAF: " + Math . Round (( sellPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / sellPositions . Sum ( p => p . VolumeInUnits )), 5 );
新しいポジションが追加されたときにVWAPの数値が自動的に更新されるように、オープンポジションを処理するイベントを追加します。
Positions . Opened += Positions_Opened ;
private void Positions_Opened ( PositionOpenedEventArgs obj )
{
var buyPositions = Positions . Where ( p => p . TradeType == TradeType . Buy );
_txtBuyVWAP . Text = "Buy Positions VWAP: " + ( buyPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / buyPositions . Sum ( p => p . VolumeInUnits ));
var sellPositions = Positions . Where ( p => p . TradeType == TradeType . Sell );
_txtSellVWAP . Text = "Sell Positions VWAP: " + ( sellPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / sellPositions . Sum ( p => p . VolumeInUnits ));
}
以下の完全なコードをコピーできます:
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
55
56
57
58
59 using System ;
using System.Linq ;
using cAlgo.API ;
namespace cAlgo.Plugins
{
[Plugin(AccessRights = AccessRights.None)]
public class MyASPExample : Plugin
{
TextBlock _txtBuyVWAP ;
TextBlock _txtSellVWAP ;
protected override void OnStart ()
{
var block = Asp . SymbolTab . AddBlock ( "ASP Section Example" );
block . Index = 2 ;
block . Height = 100 ;
block . IsExpanded = true ;
var panel = new StackPanel
{
Orientation = Orientation . Vertical
};
_txtBuyVWAP = new TextBlock
{
Text = "Buy Text Box"
};
_txtSellVWAP = new TextBlock
{
Text = "Sell Text Box"
};
panel . AddChild ( _txtBuyVWAP );
panel . AddChild ( _txtSellVWAP );
block . Child = panel ;
var buyPositions = Positions . Where ( p => p . TradeType == TradeType . Buy );
_txtBuyVWAP . Text = "Buy Positions VWAF: " + Math . Round (( buyPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / buyPositions . Sum ( p => p . VolumeInUnits )), 5 );
var sellPositions = Positions . Where ( p => p . TradeType == TradeType . Sell );
_txtSellVWAP . Text = "Sell Positions VWAF: " + Math . Round (( sellPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / sellPositions . Sum ( p => p . VolumeInUnits )), 5 );
Positions . Opened += Positions_Opened ;
}
private void Positions_Opened ( PositionOpenedEventArgs obj )
{
var buyPositions = Positions . Where ( p => p . TradeType == TradeType . Buy );
_txtBuyVWAP . Text = "Buy Positions VWAP: " + ( buyPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / buyPositions . Sum ( p => p . VolumeInUnits ));
var sellPositions = Positions . Where ( p => p . TradeType == TradeType . Sell );
_txtSellVWAP . Text = "Sell Positions VWAP: " + ( sellPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / sellPositions . Sum ( p => p . VolumeInUnits ));
}
}
}
プラグインを再度ビルドし、Trade アプリに移動します。 新しい買いと売りのポジションを追加すると、VWAPが自動的に更新されるはずです。
プラグインにスタイルを追加する VWAPボックスにスタイルを追加できます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 var textBoxStyle = new Style ();
textBoxStyle . Set ( ControlProperty . Margin , 5 );
textBoxStyle . Set ( ControlProperty . FontFamily , "Cambria" );
textBoxStyle . Set ( ControlProperty . FontSize , 16 );
textBoxStyle . Set ( ControlProperty . Width , 200 );
textBoxStyle . Set ( ControlProperty . ForegroundColor , Color . Yellow , ControlState . Hover );
_txtBuyVWAP = new TextBlock
{
ForegroundColor = Color . Green ,
Text = "Buy Text Box " ,
Style = textBoxStyle
};
_txtSellVWAP = new TextBlock
{
ForegroundColor = Color . Red ,
Text = "Sell Text Box" ,
Style = textBoxStyle
};
以下の完全なコードをコピーできます:
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 using System ;
using System.Linq ;
using cAlgo.API ;
namespace cAlgo.Plugins
{
[Plugin(AccessRights = AccessRights.None)]
public class MyASPExample : Plugin
{
TextBlock _txtBuyVWAP ;
TextBlock _txtSellVWAP ;
protected override void OnStart ()
{
var block = Asp . SymbolTab . AddBlock ( "ASP Section Example" );
block . Index = 2 ;
block . Height = 100 ;
block . IsExpanded = true ;
var panel = new StackPanel
{
Orientation = Orientation . Vertical
};
var textBoxStyle = new Style ();
textBoxStyle . Set ( ControlProperty . Margin , 5 );
textBoxStyle . Set ( ControlProperty . FontFamily , "Cambria" );
textBoxStyle . Set ( ControlProperty . FontSize , 16 );
textBoxStyle . Set ( ControlProperty . Width , 200 );
textBoxStyle . Set ( ControlProperty . ForegroundColor , Color . Yellow , ControlState . Hover );
_txtBuyVWAP = new TextBlock
{
ForegroundColor = Color . Green ,
Text = "Buy Text Box " ,
Style = textBoxStyle
};
_txtSellVWAP = new TextBlock
{
ForegroundColor = Color . Red ,
Text = "Sell Text Box" ,
Style = textBoxStyle
};
panel . AddChild ( _txtBuyVWAP );
panel . AddChild ( _txtSellVWAP );
block . Child = panel ;
var buyPositions = Positions . Where ( p => p . TradeType == TradeType . Buy );
_txtBuyVWAP . Text = "Buy Positions VWAF: " + Math . Round (( buyPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / buyPositions . Sum ( p => p . VolumeInUnits )), 5 );
var sellPositions = Positions . Where ( p => p . TradeType == TradeType . Sell );
_txtSellVWAP . Text = "Sell Positions VWAF: " + Math . Round (( sellPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / sellPositions . Sum ( p => p . VolumeInUnits )), 5 );
Positions . Opened += Positions_Opened ;
}
private void Positions_Opened ( PositionOpenedEventArgs obj )
{
var buyPositions = Positions . Where ( p => p . TradeType == TradeType . Buy );
_txtBuyVWAP . Text = "Buy Positions VWAP: " + ( buyPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / buyPositions . Sum ( p => p . VolumeInUnits ));
var sellPositions = Positions . Where ( p => p . TradeType == TradeType . Sell );
_txtSellVWAP . Text = "Sell Positions VWAP: " + ( sellPositions . Sum ( p => p . EntryPrice * p . VolumeInUnits ) / sellPositions . Sum ( p => p . VolumeInUnits ));
}
}
}
再度プラグインをビルドします。
最後に、Trade アプリに移動して、スタイルがVWAPボックスにどのように反映されたかを確認します。
概要 この記事が、アクティブシンボルパネルにウェブページやWebViewコンポーネント、テキストブロック、その他の便利なオブジェクトを追加する方法を示すのに役立ったことを願っています。