• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Save / Restore an IntervalSelector value

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

    How to Save / Restore an IntervalSelector value

    Hello,

    I wan to save and recover the value of an IntervalSelector.

    I'm trying to set its value in a XElement on Save:

    Code:
    // NTTabPage member. Required for storing elements to workspace
    protected override void Save(XElement element)
    {
    	if (element == null)
    		return;
    
    	// Save the currently selected interval
    	if (intervalSelector != null)
    	{
    		element.Add(new XElement("IntervalValue") {Value = intervalSelector.Interval.Value.ToString()});
    		element.Add(new XElement("IntervalValue2") {Value = intervalSelector.Interval.Value2.ToString()});
    	}
    }
    and later to recover it like that:

    Code:
    protected override void Restore(XElement element)
    {
    	if (element == null)
    		return;
    
    	// Restore the previously selected instrument
    	var intervalValue = element.Element("IntervalValue");
    	var intervalValue2 = element.Element("IntervalValue2");
    	if (intervalValue != null && !string.IsNullOrEmpty(intervalValue.Value) &&
    		intervalValue2 != null && !string.IsNullOrEmpty(intervalValue2.Value))
    		intervalSelector.Interval = new BarsPeriod
    		{
    			Value = Int32.Parse(intervalValue.Value),
    			Value2 = Int32.Parse(intervalValue2.Value)
    		};
    }
    However, it works only when "Duplicate" tab, but not when close / open the add on window.

    How to fix it?
    Last edited by PopovMP; 06-11-2017, 05:54 AM.

    #2
    It appears that this save / restore methods work when we save the workspace

    Comment


      #3
      Hi PopovMP,

      have a look at the "AddOnFramework"-Sample at the very bottom lines. There you can find exactly what you want.

      Comment


        #4
        Hello PopovMP,

        Yes, windows can only save with the workspace when using NinjaScript tools.

        Attached is a simple example that demonstrates.

        GoSPvC is also correct, the Addon Framework NinjaScript Basic demonstrates this as well.
        http://ninjatrader.com/support/helpG...t_overview.htm
        Attached Files
        Last edited by NinjaTrader_ChelseaB; 08-03-2017, 08:29 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Jschmelz, Yesterday, 04:45 PM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by sisenberg, Today, 07:29 AM
        1 response
        8 views
        0 likes
        Last Post sisenberg  
        Started by Oceans, Today, 02:22 AM
        2 responses
        25 views
        0 likes
        Last Post Oceans
        by Oceans
         
        Started by sisenberg, Yesterday, 08:06 PM
        1 response
        24 views
        0 likes
        Last Post sisenberg  
        Started by PLeary, Today, 06:25 AM
        1 response
        18 views
        0 likes
        Last Post NinjaTrader_SergeyS  
        Working...
        X