Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cannot add data secondary data series

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

    Cannot add data secondary data series

    Hello,
    I cannot understand why NT8 continues to say "BarsPeriodTime.Minute doesn't exist in current context" can you help me please?

    HTML Code:
    // 
    // Copyright (C) 2016, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Windows.Media;
    using System.Xml.Serialization;
    #endregion
    
    // Add this to your declarations to use StreamWriter
    using System.IO;
    
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    	public class SampleStreamWriter : Indicator
    	{
    		private string path;
    		private StreamWriter sw; // a variable for the StreamWriter that will be used 
    		private double myadx = 0;
    		
    		protected override void OnStateChange()
    		{
    			if (State == State.Configure)
    			{
          			 AddDataSeries(BarsPeriodType.Minute, 1440);
    		}
    		
    			else if(State == State.SetDefaults)
    			{
    				Calculate 		= Calculate.OnBarClose;
    				Name			= "Sample stream writer";
    				path 			= NinjaTrader.Core.Globals.UserDataDir + "MyExportFile.txt"; // Define the Path to our test file				
    			}
    			
    			// Necessary to call in order to clean up resources used by the StreamWriter object
    			else if(State == State.Terminated)
    			{
    				if (sw != null)
    				{
    					sw.Close();
    					sw.Dispose();
    					sw = null;
    				}
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			if (ToDay(Times[0][0]) != ToDay(Times[0][1]))
    			{
    			sw = File.AppendText(path);  // Open the path for writing
    			sw.WriteLine(ToDay(Times[0][0]).ToString("dd/MM/yyyy") + ";" + ToTime(Times[0][0]).ToString("HH:mm:ss") + ";" + ADX(5)[0]); // Append a new line to the file
    			sw.Close(); // Close the file to allow future calls to access the file again.
    			}
    		}
    	}
    }

    #2
    Hello,

    This is missing a using statement:

    using NinjaTrader.Data;

    You would need to add this to the top of the file.

    In this case the sample lacked this namespace because AddDataSeries is not used. To find the default namespaces, you can generate a new indicator and they will all be listed at the top.


    I look forward to being of further assistance.

    Comment


      #3
      Thanks a lot for your help

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      48 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X