วิธีสร้างปลั๊กอินสำหรับแผงสัญลักษณ์ที่ใช้งานอยู่ VIDEO
ปลั๊กอินช่วยให้สร้างส่วนใหม่ที่มีหน้าเว็บไซต์หรือส่วนประกอบ WebView อื่นๆ เครื่องคิดเลข การวิเคราะห์หรือบอร์ดข้อมูล เครื่องมือ AI ฯลฯ ใน แผงสัญลักษณ์ที่ใช้งานอยู่ (ASP) ได้ง่าย
ในบทความนี้และวิดีโอที่เกี่ยวข้อง เราจะแสดงวิธีเพิ่มส่วนใหม่ในแผงสัญลักษณ์ที่ใช้งานอยู่โดยใช้ปลั๊กอิน
สร้างปลั๊กอิน สร้างส่วน 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 เพื่อสร้างปลั๊กอิน
นำทางไปยังแอป เทรด อีกครั้งเพื่อดูว่าปลั๊กอินกำลังแสดงอะไรใน แผงสัญลักษณ์ที่ใช้งานอยู่ ในกรณีของเรา ตอนนี้เรามีส่วนประกอบ WebView ที่แสดงฟอรัม cTrader
สร้างกล่อง VWAP สำหรับตัวอย่างนี้ เราจะแทนที่ WebView ด้วยกล่องที่แสดงราคาเฉลี่ยถ่วงน้ำหนักด้วยปริมาณ (VWAP) ของโพสิชันที่เปิดอยู่ในปัจจุบัน
กลับไปที่โค้ดปลั๊กอินและลบส่วน WebView ออก
ตั้งค่าความสูงของบล็อกเป็น 100
กำหนดบล็อกข้อความสองบล็อกที่จะแสดงข้อมูลที่เกี่ยวข้อง
TextBlock _txtBuyVWAP ;
TextBlock _txtSellVWAP ;
เพิ่มแผงสำหรับกล่องข้อความ
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 ;
คุณสามารถคัดลอกโค้ดทั้งหมดด้านล่างนี้:
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
ปรับปรุงปลั๊กอิน เพิ่มตรรกะสำหรับปลั๊กอิน ไปที่โค้ดปลั๊กอินและเพิ่ม namespace ต่อไปนี้:
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 บล็อกข้อความ และวัตถุที่มีประโยชน์อื่นๆ ลงในแผง Active Symbol