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, 04: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, 07:29 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by michaelsh, Today, 04:28 PM
        0 responses
        4 views
        0 likes
        Last Post michaelsh  
        Started by Bmatarese, Today, 03:13 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by sdauteuil, Today, 12:32 PM
        4 responses
        17 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Gaterz, 09-27-2020, 05:52 PM
        10 responses
        51 views
        0 likes
        Last Post tcea9
        by tcea9
         
        Started by derivtrader, Today, 12:04 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Spencer  
        Working...
        X