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("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
                context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
                context.XmlnsDictionary.Add("pg", "http://schemas.denisvuyka.wordpress.com/wpfpropertygrid");
                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

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by JTizz, Today, 03:32 PM
                          1 response
                          33 views
                          0 likes
                          Last Post NinjaTrader_ChrisL  
                          Started by ebaydan777, Today, 02:41 PM
                          1 response
                          27 views
                          0 likes
                          Last Post NinjaTrader_ChrisL  
                          Started by aligator, Today, 02:28 PM
                          1 response
                          27 views
                          0 likes
                          Last Post NinjaTrader_ChristopherJ  
                          Started by daniel_weber8, Today, 01:21 PM
                          1 response
                          43 views
                          0 likes
                          Last Post NinjaTrader_ChristopherS  
                          Started by jungsoohuh, Today, 12:07 PM
                          1 response
                          35 views
                          0 likes
                          Last Post NinjaTrader_PaulH  
                          Working...
                          X