Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Export chart + indicator values in .CSV

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

    Export chart + indicator values in .CSV

    Hello
    I found this link below which perfectly explains how to export the values of the bars of the chart in a text file but I would also like to export the data of an indicator too.

    In mql there is the iCustom function...
    is there its equivalent?
    Do you have an example please that shows how to call an indicator and retrieve its value because I can't find it.
    Thanks for your help​

    #2
    Hello lld32308,

    Thank you for your post.

    You could use an indicator method to call the indicator and get the value for its plot(s). We have a list of default system indicator methods here:
    https://ninjatrader.com/support/help...indicators.htm

    In that reference sample, the Time, Open, High, Low, and Close are written to the text file as follows:
    Code:
    protected override void OnBarUpdate()
    {
    sw = File.AppendText(path);  // Open the path for writing
    sw.WriteLine(Time[0] + "," + Open[0] + "," + High[0] + "," + Low[0] + "," + Close[0]); // Append a new line to the file
    sw.Close(); // Close the file to allow future calls to access the file again.
    }
    ​
    An indicator's value, such as the SMA, could be added to that as well. This would also be a good time to implement the best practice of storing a reference to an indicator instance since you would be reusing the same indicator many times.
    Code:
            
    private SMA mySma;
    
    protected override void OnStateChange()
    {
    if (State == State.DataLoaded)
    {
    mySma = SMA(14);
    }
    }
    
    protected override void OnBarUpdate()
    {
    sw = File.AppendText(path);  // Open the path for writing
    sw.WriteLine(Time[0] + "," + Open[0] + "," + High[0] + "," + Low[0] + "," + Close[0] + ", SMA: " + mySma[0]); // Append a new line to the file
    sw.Close(); // Close the file to allow future calls to access the file again.
    }
    ​
    As for exporting to .CSV, StreamWriter would export to a .txt file. You could then potentially import the .txt into a .CSV. I was able to find the following publicly available page from the Microsoft Support site regarding importing a text file to Excel:
    To import a text file, you can open the file or import the text file as an external data range. To export a text file, use the Save As command.


    Please let us know if we may be of further assistance.
    Last edited by NinjaTrader_Emily; 02-15-2023, 08:36 AM.

    Comment


      #3
      Thank you for your very complete answer. A small clarification, it is a commercial indicator. Can you confirm that the procedure is the same because I am completely familiar with your platform and programming. Thank you for you precious help

      Comment


        #4
        Hello lld32308,

        Thanks for your reply.

        By commercial indicator, are you referring to a 3rd party indicator? If that is the case, then the indicator would need a public plot in order to be called from another script. There is a note in the help guide about what functionality is or isn't provided in a 3rd party indicator:
        Note: It is important to understand the functionality provided or NOT provided in a 3rd party proprietary indicator. Just because they provide an indicator that displays a bullish or bearish trend on a chart does NOT mean that you can access this trend state from their indicator. It is up to the developer of the indicator to determine what information is accessible.


        If you are unsure about whether the indicator may be called from another script or what the syntax may be to do so, you will need to reach out to the developer/vendor of the indicator for assistance.

        Please feel free to reach out with any additional questions or concerns.

        Comment

        Latest Posts

        Collapse

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