Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 Market Analyzer and StreamWriter Help!

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

    NT8 Market Analyzer and StreamWriter Help!

    Hello Ninjatrader Team,

    I would like to pull some data out of ninjatrader using StreamWriter with Market Analyzer. However, When I run the code Nothing happens but if I run the code on the Chart tap as an indicator it works.

    Here is my StreamWriter Code.
    Code:
    		protected override void OnStateChange()
    		{
    			if(State == State.SetDefaults)
    			{
    				Calculate 		= Calculate.OnPriceChange;
    				Name			= "Sample stream writer";
    				path 			= NinjaTrader.Core.Globals.UserDataDir + "MyTestFile.txt";
    				MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
    			}
    			// Necessary to call in order to clean up resources used by the StreamWriter object
    			else if(State == State.Terminated)
    			{
    				if (sw != null)
    				{
    					sw.Dispose();
    					sw = null;
    				}
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			/* The try-catch block is used for error handling.
    			In this case it is used to ensure you only have one stream object operating on the same file at any given moment. */
    			try
    			{
    				// If file at 'path' doesn't exist it will create the file. If it does exist it will append the file.
    				if (CurrentBar == 0)
    
    					sw = File.AppendText(@"C:\Data\"+ Instrument.MasterInstrument.Name+".csv");
    				//py2
    				// This is the output of all lines.	The output format is as follows: Date Open High Low Close
    				sw.WriteLine(helpexample(Close)[0]);
    			}
    			catch (Exception)
    			{
    				// Outputs the error to the log
    				Log("You cannot write and read from the same file at the same time. Please remove SampleStreamReader.", NinjaTrader.Cbi.LogLevel.Error);
    				throw;
    and here is my Indicator Code
    Code:
    if (State == State.SetDefaults)
    			{
    				Description							= @"Enter the description for your new custom Indicator here.";
    				Name								= "helpexample";
    				Calculate							= Calculate.OnPriceChange;
    				IsOverlay							= false;
    				DisplayInDataBox					= true;
    				DrawOnPricePanel					= true;
    				DrawHorizontalGridLines				= true;
    				DrawVerticalGridLines				= true;
    				PaintPriceMarkers					= true;
    				ScaleJustification					= NinjaTrader.Gui.Chart.ScaleJustification.Right;
    				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    				//See Help Guide for additional information.
    				IsSuspendedWhileInactive			= true;
    				BarsRequiredToPlot			= 0; // u need to put this here 
    				AddPlot(new Stroke(Brushes.Firebrick, 2), PlotStyle.Line, "Line");
    			
    
    
    				
    			}
    			else if (State == State.Configure)
    			{
    			
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    
    
    			Value[0] = (EMA(200)[0]);
    
    			
    			
    			
    		}
    Also I looked at the log tap no error. Please advise how to fix this issue. Thank you

    #2
    Hello,

    Thank you for the question.

    I would be happy to look this over to see what is happening. I wanted to get additional details on this first.

    I see you have provided a StreamWriter code, and an Indicator code. I am not certain on the usage in this case, do you have a Indicator that is separate of the Stream Writer code where you are calling the streamwriter from an indicator, or was this simply to show how it is being used in your script?

    It would likely be best if you can create a sample script and provide that as an export, I could then import and see exactly what you are and go from there.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I have attached the file script here for you thank you. My goal is to make the script work on Market Analyzer, but for some reason its doing nothing.
      Attached Files
      Last edited by wallsteetking; 10-22-2015, 02:57 PM.

      Comment


        #4
        Hello,

        I tested the provided files and do see this is working.

        I did note that there may have been an error in the path you had used.

        In SetDefaults you have:

        Code:
        path = NinjaTrader.Core.Globals.UserDataDir + "MyTestFile.txt";
        But in OnBarUpdate, you are not using this path, possibly from a different test. But the path variable is still likely missing a / for the file also making it invalid. Additionally, in OnBarUpdate, that path if the folder does not already exist, it would fail.

        I used the following instead to correct this and write to file successfully:


        Code:
        path = Path.Combine(NinjaTrader.Core.Globals.UserDataDir , "MyTestFile.txt")	;
        Then in OBU:

        Code:
        sw = File.AppendText(path);	
        sw.WriteLine(helpexample(Close)[0]);
        For other directories that the end user may not have, you can use something like the following as a condition to check for that:

        Code:
        if(!Directory.Exists(path)) Directory.CreateDirectory(path);
        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          did it work on market analyzer? I still did not have the time to check your updated script thank you

          Comment


            #6
            Hello,

            Yes, this was only tested in the Market Analyzer as that was the question at hand.

            Once you have had time to review, please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by wallsteetking View Post
              Here is my StreamWriter Code.
              Code:
              		protected override void OnStateChange()
              		{
              			if(State == State.SetDefaults)
              			{
              				Calculate 		= Calculate.OnPriceChange;
              				Name			= "Sample stream writer";
              				path 			= NinjaTrader.Core.Globals.UserDataDir + "MyTestFile.txt";
              				MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
              			}
              			// Necessary to call in order to clean up resources used by the StreamWriter object
              			else if(State == State.Terminated)
              			{
              				if (sw != null)
              				{
              					sw.Dispose();
              					sw = null;
              				}
              			}
              		}
              
              		protected override void OnBarUpdate()
              		{
              			/* The try-catch block is used for error handling.
              			In this case it is used to ensure you only have one stream object operating on the same file at any given moment. */
              			try
              			{
              				// If file at 'path' doesn't exist it will create the file. If it does exist it will append the file.
              				if (CurrentBar == 0)
              
              					sw = File.AppendText(@"C:\Data\"+ Instrument.MasterInstrument.Name+".csv");
              				//py2
              				// This is the output of all lines.	The output format is as follows: Date Open High Low Close
              				sw.WriteLine(helpexample(Close)[0]);
              			}
              			catch (Exception)
              			{
              				// Outputs the error to the log
              				Log("You cannot write and read from the same file at the same time. Please remove SampleStreamReader.", NinjaTrader.Cbi.LogLevel.Error);
              				throw;
              and here is my Indicator Code
              Code:
              if (State == State.SetDefaults)
              			{
              				Description							= @"Enter the description for your new custom Indicator here.";
              				Name								= "helpexample";
              				Calculate							= Calculate.OnPriceChange;
              				IsOverlay							= false;
              				DisplayInDataBox					= true;
              				DrawOnPricePanel					= true;
              				DrawHorizontalGridLines				= true;
              				DrawVerticalGridLines				= true;
              				PaintPriceMarkers					= true;
              				ScaleJustification					= NinjaTrader.Gui.Chart.ScaleJustification.Right;
              				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
              				//See Help Guide for additional information.
              				IsSuspendedWhileInactive			= true;
              				BarsRequiredToPlot			= 0; // u need to put this here 
              				AddPlot(new Stroke(Brushes.Firebrick, 2), PlotStyle.Line, "Line");
              			
              
              
              				
              			}
              			else if (State == State.Configure)
              			{
              			
              			}
              		}
              
              		protected override void OnBarUpdate()
              		{
              
              
              			Value[0] = (EMA(200)[0]);
              
              			
              			
              			
              		}
              Also I looked at the log tap no error. Please advise how to fix this issue. Thank you
              Why would you post this in NT7 forums? No wonder no one saw this.

              Comment


                #8
                Hello Jesse,

                I have tried your updated script But it still does not work ... Furthermore, I reinstalled NT8 beta and imported the original streamwriterNT8 . The same thing happens . When I go Market Analyzer load streamwriter. All I get is 3 dots "..." Nothing happens.

                Tech info:
                I am running on Windows 8
                Intel Core i7 CPU
                64bit , x65-based processor.

                The script NT7 works flawless. However, on NT8 it does not work.
                Can you please advise or another way I achieve this goal?

                Thank you

                Comment


                  #9
                  StreamWriter and Market Anlyzer does not work .

                  Hello NT8 Team,

                  StreamWriterSample and Market Analyzer does not work. When I go to Market Analyzer and load SPY as instrument >> then under indicators I click StreamWriterSample 1Day - load 50 days. Nothing Happens. Please advise

                  Comment


                    #10
                    Hello,

                    I wanted to check, what are you expecting to appear in the column aside from three dots?

                    The three dots would be expected at there is nothing being plotted in the script. As the script currently is, it would write the Close price to file as the said directory. If you also wanted a value in the MA column, you would need to plot a value.

                    Are you getting the output file? If not have you tried an exact path like "C:/TestFile.txt"

                    Please let me know if I may be of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Hello,
                      I have tested the SampleStreamWriter reference with the Marekt Analyzer and I do not receive results for calculating On Bar Close. If I have it set to On Each Tick it begins writing to the file.
                      Please test if SampleStreamWriter works for you with it set to Calculate On Each Tick.
                      Cody B.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello Jesse,

                        in the Market Analyzer I am expecting to see the closing price no 3 dots.
                        Furthermore, I am not getting the output file which is what i need.

                        This is how I set up the Market Analyzer can you please try to clone and see if you get any results. (See picture)

                        Furthermore, NinjaTrader_CodyB is having the same problem. I also tried it on Tick mode but it does not work.

                        I am connected with Kinteck end of day free connection using a demo account
                        Attached Files

                        Comment


                          #13
                          I tried Calculate On Each Tick. still nothing happens. anything other way I can download data into a txt file from nt8?

                          Comment


                            #14
                            Hello,

                            The settings being used would explain the file not being produced.

                            Currently you have this set on CalculateOnBarClose true and also on a 1 day chart. That would mean a single print per day on each bar close.

                            Was this what you had intended? If so have you waited for the daily bar to close to see if the data is written?

                            Can you instead try using a smaller series such as a 30 second or on each tick to see if the file is generated to confirm that portion of this question is resolved? During my tests I had used the MA columns default settings which would be to calculate on each tick on a 1 minute series.

                            If the file is not being generated, you likely have a problem with the path being used to the file. Have you tried Printing the path you are using to verfiy it exists and is valid? Can you try a direct path that already exists like "C:\TestFile.text" to ensure the path is correct on your end?

                            Additionally, the Close price would not be displayed because that is not what you had programmed this indicator to do, you would need to add a Plot and Plot the value of the close for the MarketAnalyzer to have any values to display. This would be the same process which you had followed to create the helpexample.cs indicator. Once you have added a Plot, you would need to remove the column and re add it for the plot to appear in the list.


                            I look forward to being of further assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Hello,

                              I had missed one item from your note which is relevant.

                              "I am connected with Kinetick end of day free connection using a demo account"

                              Can you confirm which connection you are using as the statement was not directly clear, are you connected to the Kinetick End of Day feed or a Demo live data feed? Or are you connected to both? If you have a demo live data feed, please disconnect from the end of day connection and try the indicator once again in live data only.

                              I look forward to being of further assistance.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by funk10101, Today, 12:02 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by GLFX005, Today, 03:23 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by nandhumca, Yesterday, 03:41 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by The_Sec, Yesterday, 03:37 PM
                              1 response
                              11 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by vecnopus, Today, 06:15 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post vecnopus  
                              Working...
                              X