TifSelector

View as Markdown

Definition

TifSelector can be used as a UI element users can interact with for selecting TIF.

Events and Properties

Method/PropertyDescription
Cleanup()Disposes of the TifSelector (Note: calling the NTTabPage base.Cleanup() is sufficient to clean up this control)
SelectedTifA TimeInForce representing the selected TIF
• - Possible values:
• - TimeInForce.Day
• - TimeInForce.Gtc
• - TimeInForce.Gtd
• - TimeInForce.Ioc
• - TimeInForce.Opg
SelectionChangedEvent handler for when the selected ATM strategy has changed

Examples

This example demonstrates how to use the TIF selector and properly link its behavior with the quantity up/down and TIF selectors.

1private QuantityUpDown qudSelector;
2
3private TifSelector tifSelector;
4
5private AtmStrategy.AtmStrategySelector atmStrategySelector;
6
7private DependencyObject LoadXAML()
8
9{
10
11 // Note: pageContent (not demonstrated in this example) is the page content of the XAML
12
13 // Find the Quantity Up-Down selector
14
15 qudSelector = LogicalTreeHelper.FindLogicalNode(pageContent, "qudSelector") as QuantityUpDown;
16
17 // Find the TIF selector
18
19 tifSelector = LogicalTreeHelper.FindLogicalNode(pageContent, "tifSelector") as TifSelector;
20
21 // Be sure to bind our account selector to our TIF selector to ensure proper functionality
22
23 tifSelector.SetBinding(TifSelector.AccountProperty, new Binding { Source = accountSelector,
24 Path = new PropertyPath("SelectedAccount") });
25
26 // When our TIF selector's selection changes
27
28 tifSelector.SelectionChanged += (o, args) =>
29
30 {
31
32 // Change the selected TIF in the ATM strategy too
33
34 if (atmStrategySelector.SelectedAtmStrategy != null)
35
36 atmStrategySelector.SelectedAtmStrategy.TimeInForce = tifSelector.SelectedTif;
37
38 };
39
40 // Find ATM Strategy selector and attach event handler
41
42 atmStrategySelector = LogicalTreeHelper.FindLogicalNode(pageContent, "atmStrategySelector") as AtmStrategy.AtmStrategySelector;
43
44 atmStrategySelector.Id = Guid.NewGuid().ToString("N");
45
46 if (atmStrategySelector != null)
47
48 atmStrategySelector.CustomPropertiesChanged += OnAtmCustomPropertiesChanged;
49
50 // Be sure to bind our account selector to our ATM strategy selector to ensure proper functionality
51
52 atmStrategySelector.SetBinding(AtmStrategy.AtmStrategySelector.AccountProperty,
53
54 new Binding { Source = accountSelector, Path = new PropertyPath("SelectedAccount") });
55
56 // When our ATM selector's selection changes
57
58 atmStrategySelector.SelectionChanged += (o, args) =>
59
60 {
61
62 if (atmStrategySelector.SelectedItem == null)
63
64 return;
65
66 if (args.AddedItems.Count > 0)
67
68 {
69
70 // Change the selected TIF in our TIF selector too
71
72 AtmStrategy selectedAtmStrategy = args.AddedItems[0] as AtmStrategy;
73
74 if (selectedAtmStrategy != null)
75
76 tifSelector.SelectedTif = selectedAtmStrategy.TimeInForce;
77
78 }
79
80 };
81
82}
83
84private void OnAtmCustomPropertiesChanged(object sender, NinjaScript.AtmStrategy.CustomPropertiesChangedEventArgs args)
85
86{
87
88 // Adjust our TIF and Quantity selectors to the new ATM strategy values
89
90 tifSelector.SelectedTif = args.NewTif;
91
92 qudSelector.Value = args.NewQuantity;
93
94}
95
96// NOTE: Don't forget to clean up resources and unsubscribe to events
97
98// Called by TabControl when tab is being removed or window is closed
99
100public override void Cleanup()
101
102{
103
104 // Clean up our resources
105 base.Cleanup();
106
107}
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Tools="clr-namespace:NinjaTrader.Gui.Tools;assembly=NinjaTrader.Gui"
xmlns:AccountPerformance="clr-namespace:NinjaTrader.Gui.AccountPerformance;assembly=NinjaTrader.Gui"
xmlns:AccountData="clr-namespace:NinjaTrader.Gui.AccountData;assembly=NinjaTrader.Gui"
xmlns:AtmStrategy="clr-namespace:NinjaTrader.Gui.NinjaScript.AtmStrategy;assembly=NinjaTrader.Gui">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Tools:QuantityUpDown x:Name="qudSelector" Value="1" Grid.Column="0"/>
<Tools:TifSelector x:Name="tifSelector" Grid.Column="1"/>
<AtmStrategy:AtmStrategySelector x:Name="atmStrategySelector" LinkedQuantity="{Binding Value,
ElementName=qudSelector, Mode=OneWay}" Grid.Column="2"/>
</Grid>