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

DatePicker

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

    DatePicker

    Stuck, could someone toss me a bone?

    I am using SetIndicatorValueFromAddonWindow as a guide (https://ninjatrader.com/support/foru...686#post492686) that NinjaTrader_ChelseaB created but I can not get a DatePicker to work properly.

    Issues:
    1) The Date does not show in the DatePicker either on Load or after SelectionChanged
    2) Error in the SelectionChanged event

    Here is the code from the latest attempt:

    PHP Code:
    private DatePicker        enterDate;

        private 
    DependencyObject LoadXaml()
        {
            
    DatePicker enterDate = (LogicalTreeHelper.FindLogicalNode(page"dp_EnterDate") as DatePicker) ;
            
    enterDate.SelectedDate TargetIndicator.EnterDate;

            
    //  EnterDate from Indicaor is set to Datetime.Now
            
    NinjaTrader.Code.Output.Process(string.Format("  TargetIndicator.EnterDate {0}"TargetIndicator.EnterDate   ), PrintTo.OutputTab1);
            
    NinjaTrader.Code.Output.Process(string.Format("  enterDate.Text            {0}"enterDate.Text   ), PrintTo.OutputTab1);
            
    //  These 2 Outputs above print the correct values

            
    if (enterDate != null)
                
    enterDate.SelectedDateChanged += EnterDateDropDown_SelectionChanged;
        }

        private 
    void EnterDateDropDown_SelectionChanged(object senderSelectionChangedEventArgs e)
        {
            
    NinjaTrader.Code.Output.Process("EnterDateDropDown_SelectionChanged  "PrintTo.OutputTab1);
            
    NinjaTrader.Code.Output.Process(string.Format("    sender {0}",sender) , PrintTo.OutputTab1);
            
    //  Prints: "sender 4/10/2018 12:00:00 AM"    

            
    NinjaTrader.Code.Output.Process(string.Format("    e      {0}",e) , PrintTo.OutputTab1);
            
    //  Prints: "e      System.Windows.Controls.CalendarSelectionChangedEventArgs"
            
            //  This Output throws Error
            //  "Unhandled exception: Object reference not set to an instance of an object"
            
    NinjaTrader.Code.Output.Process(string.Format("    Selected Date {0}",enterDate.SelectedDate) , PrintTo.OutputTab1);
        } 

    #2
    Hello TAJTrades,

    Thanks for the post.

    If you want to use the NinjaTrader DatePicker, you will need a reference to

    Program Files (x86)\NinjaTrader 8\bin\InfragisticsWPF4.Editors.v15.1.dll

    Then add Infragistics to the namespace in your xaml:

    Code:
    xmlns:ie="http://infragistics.com/Editors"
    Code:
    <ie:XamDateTimeEditor Grid.Column="1" Grid.Row="6" IsAlwaysInEditMode="True" x:Name="dp" Mask="{}{date}"></ie:XamDateTimeEditor>
    When you use the DatePicker in your code behind, you must fully qualify the date picker:

    Code:
    Infragistics.Windows.Editors.XamDateTimeEditor datePicker;
    Code:
    datePicker = LogicalTreeHelper.FindLogicalNode(page, "dp") as Infragistics.Windows.Editors.XamDateTimeEditor;
    You must make a nullable DateTime property in the indicator and make sure to serialize it:
    [XmlIgnore()]
    [Browsable(false)]
    public DateTime? DateValue
    { get; set; }

    [Browsable(false)]
    public string DateValueSerialize {
    get { return DateValue.ToString(); }
    set { DateValue = DateTime.Parse(value); }
    }

    I also had to cast the datePicker objects "Value" object to a nullable DateTime object:

    Code:
    if (datePicker != null)
    {
    	TargetIndicator.DateValue		= (DateTime?)datePicker.Value;
    }
    I have attached the modification to this post as well.

    Please let us know if we may be of any further assistance.
    Attached Files
    Last edited by NinjaTrader_ChrisL; 04-12-2018, 08:55 AM. Reason: Corrected export.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chris, will give it a go. I don't feel so stupid now since I have never heard of Infragistics. So I did a NT Help Guide search and nothing. Did a Google search and found https://www.infragistics.com/help/wp...age-assemblies. Is this the same thing?

      So if I wanted to use a DataGrid bound to a DataTable/DataSet to an xml file, which is easily done in VS 2015, is there any other special things that I would need? This is more for a learning experience to create a model in case there is something I might want to do in the future.

      Thanks.

      Comment


        #4
        Hello TAJTrades,

        Thanks for the reply.

        The Infragistics class is just the one NinjaTrader uses, it was not made by NinjaTrader. You can create NinjaTrader add-ons like you would any other WPF application, so you will do bindings the way you normally would. You can use the INotifyPropertyChanged Interface so the bound controls know when a property has changed.

        Enable your properties to automatically notify a binding source when the property value changes in Windows Presentation Foundation (WPF).


        Please let me know if I may be of any further assistance.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Chris:

          If you want to use the NinjaTrader DatePicker, you will need a reference to

          Program Files (x86)\NinjaTrader 8\bin\InfragisticsWPF4.Editors.v13.2.dll
          My NT version is 8.0.13.1 64 Bit

          I don't have
          InfragisticsWPF4.Editors.v13.2.dll

          but I do have
          InfragisticsWPF4.Editors.v15.1.dll

          Is this just an updated file? Or is my NT Install messed up? Thought I would ask before I mortally wounded the NT.

          Thanks

          Comment


            #6
            Hello TAJTrades,

            Thanks for the reply.

            I have v15.1 as well, I will update my previous post.

            Please let us know if you have any questions.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Chris,

              I am getting an error importing the File. Msg Box reads
              HTML Code:
              "Error   The NinjaScript Archive File does not contain an info.xml file or is corrupt.  Please check the Archive File"
              Have no idea why the xml file throw an error on normal Import.

              So I tried the manual way.
              1) Unzipped the NT Zip file and then copied the files into NT8.
              2) Opened the NinjaScript editor and selected the Indicator file and tried to compile.

              Received Error Msg
              HTML Code:
              The type "Infragistics.Windows.Commands.ICommandHost" is defined in an asseembly that is not referenced.  You must add a reference to assembly "InfragisticsWPF4,v15.1, version =15.1.20151.2055, Culture=neutral, PublicTokenKey=7dd5c3163f2cd0cb".
              So I hunted around and found the file and added the reference.

              It compiled and appears to work. Did I do this correctly?

              Last Question:
              In the Indicator file the following is Commented Out. Reason? If not Commented Out how would it effect the script? Will it effect on the xaml? Or does it act just like a normal Indicator Script i.e Brush?
              HTML Code:
              //  [Browsable(false)]
              //  public string DateValueSerialize {
              //  get{ return DateValue.ToString()(;}
              //  set{ DateValue = DAteTime.Parse(value);}
              // }
              Many thanks for your help. I would have never figured this out on my own.
              Last edited by TAJTrades; 04-12-2018, 04:10 PM.

              Comment


                #8
                Hello TAJTrades,

                Thanks for the follow up.

                Sorry about the importing issue. You did get it right though if the script is running in NinjaTrader.

                The commented out property is for serialization of the DateTime object. This is for saving the date setting when you save your workspace. You can uncomment that if you need to save the date that the date selector is set to between launches of NinjaTrader.
                Chris L.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bmartz, 03-12-2024, 06:12 AM
                5 responses
                32 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by Aviram Y, Today, 05:29 AM
                4 responses
                12 views
                0 likes
                Last Post Aviram Y  
                Started by algospoke, 04-17-2024, 06:40 PM
                3 responses
                28 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by gentlebenthebear, Today, 01:30 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by cls71, Today, 04:45 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X