Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

SetIndicatorValueFromAddonWindowExample - Brush Property Does not Update

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    SetIndicatorValueFromAddonWindowExample - Brush Property Does not Update

    I have tried amending SetIndicatorValueFromAddonWindowExample by adding another field of System.Media.Brush in the indicator and I added combobox in the xaml file containing list of colors customised to show border with background equals the color chosen and text block showing the name of color similar to NinjaScript Brush property grid. However, when window is opened every field gets updated and saved from OKButton event except the brush. Here is the xaml code:

    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:t="clr-namespace:NinjaTrader.Gui.Tools;assembly=NinjaTrad er.Gui"
    xmlns:sys="clr-namespace:System;assembly=mscorlib">

    <Page.Resources>
    <!-- Make sure this namespace is declared so that it's in scope below -->
    <ObjectDataProvider MethodName="GetType"
    ObjectType="{x:Type sys:Type}" x:Key="colorsTypeOdp">
    <ObjectDataProvider.MethodParameters>
    <sys:String>System.Windows.Media.Colors, PresentationCore,
    Version=3.0.0.0, Culture=neutral,
    PublicKeyToken=31bf3856ad364e35</sys:String>
    </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
    <ObjectDataProvider ObjectInstance="{StaticResource colorsTypeOdp}"
    MethodName="GetProperties" x:Key="colorPropertiesOdp">
    </ObjectDataProvider>
    </Page.Resources>
    <Grid>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="15" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="15" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition Height="10" />
    <RowDefinition Height="25" />
    <RowDefinition Height="28" />
    <RowDefinition Height="25" />
    <RowDefinition Height="28" />
    <RowDefinition Height="25" />
    <RowDefinition Height="28" />
    <RowDefinition Height="30" />
    <RowDefinition Height="28" />
    <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Label Grid.Column="1" Grid.Row="1" Content="Set Instrument" Foreground="#CCCCCC" HorizontalAlignment="Left" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Top "/>
    <t:InstrumentSelector x:Name="InstrumentSelectorInput" Grid.Row="2" Grid.Column="1" LastUsedGroup="SetIndicatorValueFromAddonExample" VerticalAlignment="Top">
    <t:InstrumentSelector.Margin>
    <Thickness Left="{StaticResource MarginBase}" Top="{StaticResource PaddingColumn}" Bottom="0 "/>
    </t:InstrumentSelector.Margin>
    </t:InstrumentSelector>
    <Label Grid.Column="1" Grid.Row="3" Content="Set integer value" HorizontalAlignment="Left" VerticalAlignment="Top" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="#CCCCCC" />
    <t:QuantityUpDown x:Name="QuantityUpDownInput" Grid.Row="4" Grid.Column="1" Value="1">
    <t:QuantityUpDown.Margin>
    <Thickness Left="{StaticResource MarginBase}" Top="{StaticResource MarginControl}" Bottom="0" />
    </t:QuantityUpDown.Margin>
    </t:QuantityUpDown>
    <Label Grid.Column="1" Grid.Row="5" Content="Set string value" HorizontalAlignment="Left" VerticalAlignment="Top" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="#CCCCCC" />
    <TextBox x:Name="StringValueInput" Grid.Column="1" Grid.Row="6" Text="Sample Text" VerticalAlignment="Top">
    <TextBox.Margin>
    <Thickness Left="{StaticResource MarginBase}" Top="{StaticResource MarginControl}" Bottom="0" />
    </TextBox.Margin>
    </TextBox>

    <ComboBox Name="BrushComboBox" Grid.Row="7" Grid.Column="1"
    ItemsSource="{Binding Source={StaticResource colorPropertiesOdp}}"
    SelectedValuePath="Name">
    <ComboBox.ItemTemplate>
    <DataTemplate>
    <StackPanel Orientation="Horizontal" Height="18" Margin="0,0,0,2">
    <Border BorderThickness="1" CornerRadius="2"
    BorderBrush="Black" Width="50" VerticalAlignment="Stretch"
    Background="{Binding Name}"/>
    <TextBlock Text="{Binding Name}" Margin="8,0,0,0"/>
    </StackPanel>
    </DataTemplate>
    </ComboBox.ItemTemplate>
    </ComboBox>

    <StackPanel Grid.Column="1" Grid.Row="8" HorizontalAlignment="Right" Orientation="Horizontal">
    <Button x:Name="OkButton" Content="Ok" Width="50 "/>
    <Button x:Name="CancelButton" Content="Cancel" Width="50 "/>
    </StackPanel>
    </Grid>
    </Page>​
    and here the code:

    public class IndicatorWindowDataManagementNTWindow : NTWindow
    {
    private Button cancelButton;
    private InstrumentSelector instrumentSelectorInput;
    private Instrument instrumentValue;
    private Button okButton;
    private QuantityUpDown quantityUpDownInput;
    private TextBox stringValueInput;

    private ComboBox combo;

    private Brush brush;

    public Indicators.SetIndicatorValueFromAddonWindowExample TargetIndicator;

    public IndicatorWindowDataManagementNTWindow()
    {
    Caption = "IndicatorWindow Data Management Tools";
    Width = 400;
    Height = 250;
    Height = 10050;

    Loaded += OnWindow_Loaded;
    Closing += OnWindow_Close;
    }

    private void OnWindow_Loaded(object sender, RoutedEventArgs e)
    {
    Content = LoadXaml();
    }

    private void OnWindow_Close(object sender, System.ComponentModel.CancelEventArgs e)
    {
    if (cancelButton != null)
    cancelButton.Click -= OnCancelButton_Click;

    if (instrumentSelectorInput != null)
    instrumentSelectorInput.InstrumentChanged -= OnInstrument_Changed;

    if (okButton != null)
    okButton.Click -= OnOkButton_Click;
    }

    private DependencyObject LoadXaml()
    {
    Page page = new Page();

    FileStream fs = new FileStream(System.IO.Path.Combine(NinjaTrader.Core .Globals.UserDataDir, @"bin\Custom\Xaml\SetIndicatorValueFromAddonWin dow ExampleToolsContent.xaml"), FileMode.Open);

    page = (Page)XamlReader.Load(fs);

    if (page == null)
    return null;

    cancelButton = LogicalTreeHelper.FindLogicalNode(page, "CancelButton") as Button;
    if (cancelButton != null)
    cancelButton.Click += OnCancelButton_Click;

    okButton = LogicalTreeHelper.FindLogicalNode(page, "OkButton") as Button;
    if (okButton != null)
    okButton.Click += OnOkButton_Click;

    instrumentSelectorInput = LogicalTreeHelper.FindLogicalNode(page, "InstrumentSelectorInput") as InstrumentSelector;
    if (instrumentSelectorInput != null)
    instrumentSelectorInput.InstrumentChanged += OnInstrument_Changed;

    quantityUpDownInput = LogicalTreeHelper.FindLogicalNode(page, "QuantityUpDownInput") as QuantityUpDown;
    stringValueInput = LogicalTreeHelper.FindLogicalNode(page, "StringValueInput") as TextBox;

    combo = LogicalTreeHelper.FindLogicalNode(page, "BrushComboBox") as ComboBox;
    if (combo != null)
    combo.SelectionChanged += OnSelectionChanged;

    DependencyObject pageContent = page.Content as DependencyObject;

    return pageContent;
    }

    private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    if (TargetIndicator == null)
    return;
    }

    private void OnCancelButton_Click(object sender, RoutedEventArgs e)
    {
    this.Close();
    }

    private void OnInstrument_Changed(object sender, EventArgs e)
    {
    instrumentValue = sender as Cbi.Instrument;

    brush = combo.SelectedItem as Brush;

    }

    private void OnOkButton_Click(object sender, RoutedEventArgs e)
    {
    if (TargetIndicator == null)
    return;

    if (instrumentValue != null)
    TargetIndicator.InstrumentValue = instrumentValue;

    if (quantityUpDownInput != null)
    TargetIndicator.IntValue = quantityUpDownInput.Value;

    if (stringValueInput != null)
    TargetIndicator.StringValue = stringValueInput.Text;

    if (combo != null)
    TargetIndicator.MyBrush = brush;

    TargetIndicator.ShowValues();

    this.Close();
    }
    }​

    I can't figure out where is the problem with the code.

    #2
    Hello Salmanyom,

    Thanks for your post.

    The inquiry you have reported would go beyond the support we would be able to assist you with in the Support department at NinjaTrader.

    You could consider using prints in the script to make sure the code in your script that is having a problem is being run.

    Note that the sample code was a proof of concept but may have limitations.

    This forum thread will be open for other community members to share their insights on this.
    Last edited by NinjaTrader_BrandonH; 05-22-2023, 11:16 AM.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by llanqui, Today, 03:53 AM
    0 responses
    3 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    14 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    14 views
    0 likes
    Last Post strategist007  
    Working...
    X