1+ // -------------------------------------------------------------------------------------------------
2+ //
3+ // This code is a cTrader Algo API example.
4+ //
5+ // The code is provided as a sample only and does not guarantee any particular outcome or profit of any kind. Use it at your own risk.
6+ //
7+ // This example plugin adds a new section to Trade Watch, featuring a two-by-two grid that displays information about the last known bar prices.
8+ //
9+ // For a detailed tutorial on creating this plugin, watch the video at: https://youtu.be/0HB-rdwpMAY
10+ //
11+ // -------------------------------------------------------------------------------------------------
12+ 13+ using System ;
14+ using cAlgo . API ;
15+ using cAlgo . API . Collections ;
16+ using cAlgo . API . Indicators ;
17+ using cAlgo . API . Internals ;
18+ 19+ namespace cAlgo . Plugins
20+ {
21+ [ Plugin ( AccessRights = AccessRights . None ) ]
22+ public class PreviousBarInfo : Plugin
23+ {
24+ 25+ Bars _bars ;
26+ Grid _grid ;
27+ TextBlock _lowBlock ;
28+ TextBlock _openBlock ;
29+ TextBlock _highBlock ;
30+ TextBlock _closeBlock ;
31+ 32+ protected override void OnStart ( )
33+ {
34+ var tradeWatchTab = TradeWatch . AddTab ( "Previous Bar Info" ) ;
35+ tradeWatchTab . IsSelected = true ;
36+ 37+ var webView = new WebView ( ) ;
38+ tradeWatchTab . Child = webView ;
39+ 40+ webView . NavigateAsync ( "https://ctrader.com/" ) ;
41+ 42+ _grid = new Grid ( 2 , 2 )
43+ {
44+ HorizontalAlignment = HorizontalAlignment . Center ,
45+ VerticalAlignment = VerticalAlignment . Center ,
46+ ShowGridLines = true ,
47+ Height = 150 ,
48+ Width = 150 ,
49+ } ;
50+ 51+ _bars = MarketData . GetBars ( TimeFrame . Minute , "USDJPY" ) ;
52+ 53+ _lowBlock = new TextBlock
54+ {
55+ Text = "Low:" + _bars . LowPrices . LastValue ,
56+ HorizontalAlignment = HorizontalAlignment . Center ,
57+ VerticalAlignment = VerticalAlignment . Center ,
58+ } ;
59+ 60+ _highBlock = new TextBlock
61+ {
62+ Text = "High:" + _bars . HighPrices . LastValue ,
63+ HorizontalAlignment = HorizontalAlignment . Center ,
64+ VerticalAlignment = VerticalAlignment . Center ,
65+ } ;
66+ 67+ _closeBlock = new TextBlock
68+ {
69+ Text = "Close:" + _bars . ClosePrices . LastValue ,
70+ HorizontalAlignment = HorizontalAlignment . Center ,
71+ VerticalAlignment = VerticalAlignment . Center ,
72+ } ;
73+ 74+ _openBlock = new TextBlock
75+ {
76+ Text = "Open:" + _bars . OpenPrices . LastValue ,
77+ HorizontalAlignment = HorizontalAlignment . Center ,
78+ VerticalAlignment = VerticalAlignment . Center ,
79+ } ;
80+ 81+ _grid . AddChild ( _lowBlock , 0 , 0 ) ;
82+ _grid . AddChild ( _highBlock , 0 , 1 ) ;
83+ _grid . AddChild ( _openBlock , 1 , 0 ) ;
84+ _grid . AddChild ( _closeBlock , 1 , 1 ) ;
85+ 86+ tradeWatchTab . Child = _grid ;
87+ 88+ _bars . Tick += _bars_Tick ;
89+ 90+ 91+ }
92+ 93+ private void _bars_Tick ( BarsTickEventArgs obj )
94+ {
95+ _lowBlock . Text = "Low: " + _bars . LowPrices . LastValue . ToString ( ) ;
96+ _highBlock . Text = "High: " + _bars . HighPrices . LastValue . ToString ( ) ;
97+ _openBlock . Text = "Open: " + _bars . OpenPrices . LastValue . ToString ( ) ;
98+ _closeBlock . Text = "Close: " + _bars . ClosePrices . LastValue . ToString ( ) ;
99+ }
100+ 101+ protected override void OnStop ( )
102+ {
103+ // Handle Plugin stop here
104+ }
105+ }
106+ }
0 commit comments