Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TypeConverter to allow a string input parameter

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

    TypeConverter to allow a string input parameter

    Hi NinjaTrader !
    I was trying to find the way a user can input a long text, including CR ( several rows of data ), but cant find the way on Ninja 8
    Do I need to use some TypeConverter ?
    Any help or example please ?

    #2
    Hello henrymiles, thanks for your note.

    I tested out the Text drawing tool and if you hold shift+enter while editing its text, new lines will be created. It uses this property:

    Code:
            private String text;
            //private        bool                            needsLayoutUpdate;
            [ExcludeFromTemplate]
            [Display(ResourceType = typeof(Custom.Resource), Name = "NinjaScriptDrawingToolText", GroupName = "NinjaScriptGeneral", Order = 1)]
            [PropertyEditor("NinjaTrader.Gui.Tools.MultilineEditor")]
            public string DisplayText
            {
                get { return text; }
                set
                {
                    if (text == value)
                        return;
                    text                = value;
                    //needsLayoutUpdate    = true;
                }
            }
    It looks like using this in an indicator does not work, it will only function in a DrawingTool. I will submit a feature request to our dev team to give the same functionality to the Indicators/Strategies property grid.

    As an alternative, you can either have the user select a .txt file with a file picker property or add multiple string properties.

    This code implements a custom file picker:

    Create a custom file picker in the addon namespace:

    Code:
    namespace NinjaTrader.NinjaScript.AddOns
    {
        public class CustomFilePicker : PropertyEditor
        {
            public CustomFilePicker()
            {
                InlineTemplate = CreateTemplate();
            }
    
            DataTemplate CreateTemplate()
            {
                const string xamlTemplate =
    
    @"
    <DataTemplate>
          <Grid>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width=""30""/>
              <ColumnDefinition Width=""*""/>
            </Grid.ColumnDefinitions>
        <Button Grid.Column=""0"" Content=""..."" Padding=""0"" Margin=""0""
                  HorizontalAlignment=""Stretch"" VerticalAlignment=""Stretch""
                  HorizontalContentAlignment=""Center""
                  MinWidth=""30""
                  Width=""30""
                  MaxWidth=""30""
                  Command =""pg:PropertyEditorCommands.ShowDialogEditor""
                  CommandParameter=""{Binding}"" />
            <TextBox Grid.Column=""1""
                     Text=""{Binding StringValue}""
                     ToolTip=""{Binding Value}""/>
          </Grid>
    </DataTemplate>
    ";
    
                ParserContext context = new ParserContext();
                context.XmlnsDictionary.Add("", "[URL="http://schemas.microsoft.com/winfx/2006/xaml/presentation%22"]http://schemas.microsoft.com/winfx/2006/xaml/presentation"[/URL]);
                context.XmlnsDictionary.Add("x", "[URL="http://schemas.microsoft.com/winfx/2006/xaml%22"]http://schemas.microsoft.com/winfx/2006/xaml"[/URL]);
                context.XmlnsDictionary.Add("pg", "[URL="http://schemas.denisvuyka.wordpress.com/wpfpropertygrid%22"]http://schemas.denisvuyka.wordpress.com/wpfpropertygrid"[/URL]);
                DataTemplate template = (DataTemplate)XamlReader.Parse(xamlTemplate, context);
                return template;
            }
    
            public override void ClearValue(PropertyItemValue propertyValue, IInputElement commandSource)
            {
                if (propertyValue == null || propertyValue.IsReadOnly)
                {
                    return;
                }
    
                propertyValue.StringValue = string.Empty;
            }
    
            public override void ShowDialog(PropertyItemValue propertyValue, IInputElement commandSource)
            {
                PropertyGrid propGrid = commandSource as PropertyGrid;
                string lastPath = propertyValue.StringValue;
    
                if (propGrid == null) return;
    
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "All files (*.*)|*.*";
                openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                openFileDialog.ShowDialog();
    
                propertyValue.StringValue = openFileDialog.FileName != String.Empty ? openFileDialog.FileName : lastPath; // change this string and compile, the ui does not see this change
    
                propGrid.DoReload();
    
                propGrid.RaiseEvent(new PropertyValueChangedEventArgs(PropertyGrid.PropertyValueChangedEvent, propertyValue.ParentProperty, ""));
            }
        }
    }
    Then use the file picker in a script:

    Code:
    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.NinjaScript.AddOns.CustomFilePicker")]
    [Display(Name="Image1 File Path", Description="File Path for Image1", Order=15, GroupName="5. Images")]
    public string Image1Path
    { get; set; }
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks !
      I will give it a try

      Comment


        #4
        Do I need to add a spacific using declaration ? because I get an error stating that PropertyEditor could not be found

        Comment


          #5
          Hello henrymiles,

          Yes, It looks like I deleted my test script on accident, I have included my using declarations below, Let me know if you can't compile after this:

          For the Addon:

          Code:
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows;
          using System.Windows.Controls.WpfPropertyGrid;
          using System.Windows.Input;
          using System.Windows.Media;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Core;
          using NinjaTrader.Gui;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.SuperDom;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.Gui.Tools.LoadingDialog;
          For the indicator:

          Code:
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows;
          using System.Windows.Controls.WpfPropertyGrid;
          using System.Windows.Input;
          using System.Windows.Media;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Gui;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.SuperDom;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.NinjaScript.DrawingTools;
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Now it found PropertyEditor, but missing ParserContent, XamlReader and OpenFileDialog

            Comment


              #7
              Hi henrymiles, Let me look through my deleted files and see if I can find my test script for this, please stand by.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Hello, I attached my test script here. It looks like two things are missing: 1. If you have not added a reference to System.Windows.Controls.WpfPropertyGrid.dll, do so now. Right click the editor>References>Navigate to C:\Program Files (x86)\NinjaTrader 8\bin> Select the System.Windows.Controls.WpfPropertyGrid.dll to add the reference.

                After this, add "using Microsoft.Win32;" for the OpenFileDialouge in the addon.
                Attached Files
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Yes, now it works.... but just noticed it is just a file selector ...
                  Why not using just
                  [Display(Name="Image2 File Path", Description="File Path for Image2", Order=16, GroupName="5. Images")]
                  [PropertyEditor("NinjaTrader.Gui.Tools.FilePathPick er", Filter="TXT Files (*.txt)|*.txt")]
                  public string Image2Path
                  { get; set; }
                  This do not needs an Addon... and the result is almost the same ?

                  PS : I need a multiline string input selector and the [PropertyEditor("NinjaTrader.Gui.Tools.MultilineEdi tor")] would be excellent...
                  ...can we ask to have it on indicators please ?

                  Comment


                    #10
                    Interesting that "NinjaTrader.Gui.Tools.FilePathPicker" works and "NinjaTrader.Gui.Tools.MultilineEditor" doesnt....

                    On NinjaTrader 7 this method used to work :

                    public string[] Multiple_Strings
                    {
                    get { return string_vector; }
                    set { string_vector = value; }
                    }

                    ...but not working on Ninja 8
                    pmaglio
                    NinjaTrader Ecosystem Vendor - The Indicator Store

                    Comment


                      #11
                      Hi,

                      I have added a feature request to add a multi-line string editor to the indicator property window. We will receive a feature tracking ID shortly.
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_ChrisL View Post
                        Hi,

                        I have added a feature request to add a multi-line string editor to the indicator property window. We will receive a feature tracking ID shortly.
                        Hi ,

                        Any news about that ?
                        I just need a way to allow users to type a multi line string, something like this .
                        Im sure there must be already something similar available...

                        Thanks
                        Pablo
                        pmaglio
                        NinjaTrader Ecosystem Vendor - The Indicator Store

                        Comment


                          #13
                          Hi, thanks for the follow up.

                          We are tracking your request under ID# SFT-4176. Please check the release notes upon future updates to check for added features:

                          https://ninjatrader.com/support/help...ease_notes.htm

                          Currently, there are no supported ways of doing it, but I will ask for more information from our development team on how to get this to work for a strategy/indicator.

                          Edit: We will continue to track the feature request. For now there's no way to get this in the strategy/indicator property grid.

                          I look forward to assisting you.
                          Last edited by NinjaTrader_ChrisL; 07-06-2020, 01:14 PM.
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_ChrisL View Post
                            Hello, I attached my test script here. It looks like two things are missing: 1. If you have not added a reference to System.Windows.Controls.WpfPropertyGrid.dll, do so now. Right click the editor>References>Navigate to C:\Program Files (x86)\NinjaTrader 8\bin> Select the System.Windows.Controls.WpfPropertyGrid.dll to add the reference.

                            After this, add "using Microsoft.Win32;" for the OpenFileDialouge in the addon.
                            Hi,

                            Can you update this zip file, as it seems to be the old version due to Microsoft.Win32?

                            We are moving toward Win64.

                            Note: Win32 is good for computers with 4GB or smaller RAM.

                            Comment


                              #15
                              Hi, thanks for posting. Ther is no Microsoft.Win64 namespace. See here for an explanation :

                              https://stackoverflow.com/questions/...in64-namespace (publicly available)

                              Best regards,
                              -ChrisL
                              Chris L.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post nandhumca  
                              Started by The_Sec, Today, 03:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Started by GwFutures1988, Today, 02:48 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by ScottWalsh, 04-16-2024, 04:29 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by frankthearm, Today, 09:08 AM
                              10 responses
                              36 views
                              0 likes
                              Last Post frankthearm  
                              Working...
                              X