• 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 harjinderjit, Today, 08:24 PM
        0 responses
        18 views
        0 likes
        Last Post harjinderjit  
        Started by Againmain1, Today, 03:04 AM
        1 response
        24 views
        1 like
        Last Post NinjaTrader_ShawnB  
        Started by jmahon, Yesterday, 11:44 PM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by Tomhgriff1, 01-03-2020, 04:07 AM
        4 responses
        49 views
        0 likes
        Last Post bkonia
        by bkonia
         
        Started by cary1267, Today, 09:37 AM
        1 response
        25 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Working...
        X