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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      29 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      46 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X