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

How to Save / Restore two InstrumentSelector values

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

    How to Save / Restore two InstrumentSelector values

    Hello

    I want to be able to save and restore 2 instrumentselectors that I keep in an addons that I am developing, but when I open the addons, only the value of one of them is restored in both instrumentselectors. Could you give me a nudge with the logic that I must follow in order to be able to save and restore both Selectors separately?
    Code:
     protected override void Restore(XElement element)
    {
    if (element == null)
    return;
    
    // Restore the Second selected instrument
    XElement instrumentElement = element.Element("Instrument");
    if (instrumentElement != null && !string.IsNullOrEmpty(instrumentElement.Value))
    Instrument = Cbi.Instrument.GetInstrument(instrumentElement.Value);
    
    [SIZE=14px][B]// Restore the Second selected instrument
    XElement instrumentElementMaster = element.Element("InstrumentMaster");
    if (instrumentElementMaster != null && !string.IsNullOrEmpty(instrumentElementMaster.Value))
    InstrumentMaster = Cbi.Instrument.GetInstrument(instrumentElementMast er.Value);[/B][/SIZE]
    }
    Code:
    protected override void Save(XElement element)
    {
    if (element == null)
    return;
    
    // Save the First selected instrument
    if (Instrument != null)
    element.Add(new XElement("Instrument") { Value = Instrument.FullName });
    
    [SIZE=14px][B]// Save the Second selected instrument
    if (InstrumentMaster != null)
    element.Add(new XElement("InstrumentMaster") { Value = InstrumentMaster.FullName.ToString() });[/B][/SIZE]
    I don't get any error, just when I close and open the addons the second selector is restored with the value of the first selector. The second instrument selector works correctly and I have already tried it, all I want is to restore the value that was selected before closing the addons.

    Click image for larger version

Name:	imagen.PNG
Views:	314
Size:	25.4 KB
ID:	1146941

    #2
    Hello jleira, thanks for your post.

    The element looks like it's not being saved properly when Save() is called. Have you confirmed what the value of InstrumentMaster.FullName.ToString() is when Save() is called? If you could make a reduced example addon with only the two instruments and demonstrates the issue I can test it out on my end to see what the problem is after you have fonfirmed what InstrumentMaster.FullName is.

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello NinjaTrader_ChrisL

      I have done the test you indicated and I see that Instrument.Fullname and InstrumentMaster.Fullname keep their own values separately. Attached photo of Output 1.

      I share a reduced code with you.

      [ATTACH]n1147212[/ATTACH]
      Attached Files

      Comment


        #4
        Hello jleira, thanks for posting the reduced sample. I am able to save the selected instrument for each Instrument selector in the workspace. Are you getting something different testing this reduced script? If so please first make sure you are running the latest version of NinjaTrader by running the installer from this page:
        NinjaTrader is a futures trading platform that delivers integrated multi-device trading. Discover our best platform to trade futures for active futures traders.


        I look forward to hearing from you.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello

          It just can not be. It does not work for me. For example if I open the testAddons and in either of the two selectors I change the instrument, save the workspace and close the testAddons, when I open the testAddons again, in both selectors the instrument that had changed is restored and I do not want that but in each selector The instrument that was selected before closing the testAddons is restored.

          I already have the latest version of NinjaTrader 8.0.24.1

          Did each selector restore you with a different instrument?

          Comment


            #6
            Hello jleira, thanks for your reply.

            The workspace will save the values that you set from the single window instance. If you close out the window instance and start a new one it would go back to the default values. If you exit NinjaTrader with the same window instance it will keep the selected value. If you need some templating system where a default template is loaded every time you open a new window that would need to be implemented as a feature of your addon, there's is no helper code for templates in the addon framework.

            Please let me know if this does not resolve your inquiry.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi ChrisL

              I don't think you understood the problem I was having. What was happening is that if you had made a change in an instrument selector before closing the addon window, that same instrument was restored in both instrument selectors when you opened the addon window again and that was wrong.

              But I found something on the instrument selector line in the XAML file. LastUsedGroup = "AddOnFramework". Both instrument selectors showed the same name "AddOnFramework" so I changed the name of each one.
              This solved the issue and now, if I close the Addon window and reopen it, each instrument selector is restored separately with the instrument it had before it was closed.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Waxavi, Today, 02:10 AM
              0 responses
              2 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by TradeForge, Today, 02:09 AM
              0 responses
              4 views
              0 likes
              Last Post TradeForge  
              Started by Waxavi, Today, 02:00 AM
              0 responses
              2 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by elirion, Today, 01:36 AM
              0 responses
              4 views
              0 likes
              Last Post elirion
              by elirion
               
              Started by gentlebenthebear, Today, 01:30 AM
              0 responses
              4 views
              0 likes
              Last Post gentlebenthebear  
              Working...
              X