Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Export Indicator Values

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

    Export Indicator Values

    Hello,
    I'm trying to export OHLC data along with a few indicator values to a csv file. I've referenced the streamwriter indicator file here (https://ninjatrader.com/support/foru...xt-file?t=3475) and got it to work with just the OHLC data. But if I add an indicator value such as BuySellPressure.BuyPressure[0] I get 'BuySellPressure() is a method which is not valid in the given context'. I've tried a few different indicator plots all with similar results. This technique for exporting indicator values worked in NT7 but I cant seem to figure it out in NT8. Thanks.

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    
    
    using System.IO;
    // Add this to your declarations to use StreamWriter
    
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class AStreamWriter : Indicator
    {
    private string path;
    private StreamWriter sw; // a variable for the StreamWriter that will be used
    
    protected override void OnStateChange()
    {
    if(State == State.SetDefaults)
    {
    Calculate = Calculate.OnBarClose;
    Name = "Astream writer";
    
    }
    
    // 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;
    }
    }
    else if(State == State.Configure)
    {
    path = "c:\\dataexport\\txt\\" + Instrument.FullName +".txt"; // Define the Path to our test file
    }
    }
    
    protected override void OnBarUpdate()
    {
    sw = File.AppendText(path); // Open the path for writing
    string data = (Time[0].ToString("MM/dd/yyyy;HH:mm:ss")) + ";" + Open[0] + ";" + High[0] + ";" + Low[0] + ";" + Close[0] + ";" + Volume[0] + ";" + BuySellPressure.BuyPressure[0];
    sw.WriteLine(data);
    sw.Close(); // Close the file to allow future calls to access the file again.
    }
    }
    }

    #2
    You are using bar array index[x] when you should be using an absolute value for the method BuySellPressure.

    E.g Volume is part of the Bars series so uses index array value which is enclosed by square brackets[]. BuySellPressure is a method which is accessed using absolute value in normal brackets ()

    "Volume[0] + ";" + BuySellPressure.BuyPressure[0]" *****method not accessed using square bracket index.

    Try, BuySellPressure.BuyPressure(CurrentBar)

    Comment


      #3
      Welcome to the forums dirkdiggler87!

      As a tip, you could use the Strategy Builder to create logic that checks this indicator's plot, and then you can use the View Code button to see the resulting syntax.

      Code:
      public class MyCustomStrategy13 : Strategy
      {
         private BuySellPressure BuySellPressure1; // See here
      
         protected override void OnStateChange()
         {
            if (State == State.SetDefaults)
            {
               ...
            }
            else if (State == State.DataLoaded)
            {
               BuySellPressure1 = BuySellPressure(Close); // See here
            }
         }
      
         protected override void OnBarUpdate()
         {
            if ([B]BuySellPressure1.BuyPressure[0][/B] == 0) // See here
            {
            }
          }
      }
      We look forward to assisting.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      581 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      336 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X