Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

external date for indicator construction

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

    external date for indicator construction

    I would like to create custom indicators with data that are not normally available in NT7. Therefore I would like to import such data from an external source for instance a text file. Is there any way to read external data like in the following example to use it in the coding of custom indicators?

    Date, Number of Stocks
    2015-04-23, 2086
    2015-04-22, 1782
    2015-04-21, 1578
    2015-04-20, 2189
    2015-04-17, 629
    2015-04-16, 1378
    2015-04-15, 2085
    2015-04-14, 1965
    2015-04-13, 1178
    2015-04-10, 1860

    #2
    Hello Atreio,

    Thank you for your post.

    You can read from an external file using the reference at the following link: http://www.ninjatrader.com/support/f...ead.php?t=3476

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

    Comment


      #3
      Thanks for your reply.

      I have still a few problems. I understand that the skript produces an output in the output window, not in a chart window. But how do I ran a script, if not in a Chart or a market analyzer?

      Comment


        #4
        Hello Atreio,

        Thank you for your response.

        The output is to the Output window but you can add the indicator to your chart or Market Analyzer.

        Are you looking to store the data read into a data series that can be used much like the Close[0] for example?

        Comment


          #5
          Yes, I would like to produce a data series, to use it as an indicator. But I think even the original script is not running yet. If I load the zip file and apply the indicator to a chart window without changing anything in the code, I think I should see at least the following message in the Output box.

          "File does not exist."
          Last edited by Atreio; 05-07-2015, 07:39 AM.

          Comment


            #6
            Hello Atreio,

            Thank you for your response.

            Have you created the "MyTestFile.txt" file in the (My) Documents\NinjaTrader 7 directory on your PC?
            Have you changed the private string path?

            Comment


              #7
              I left the private string path unchanged

              privatestring path = Cbi.Core.UserDataDir.ToString() + "MyTestFile.txt";

              and put the MyTestFile.txt to this folder

              D:\Documents and Settings\My Documents\NinjaTrader 7

              Comment


                #8
                Hello Atreio,

                If the file exists then you would not see that message.

                Have you implemented the StreamReader into your own code and used your own text file to read from?

                Comment


                  #9
                  Well, I tried both, with and without the file in the Folder.

                  No, I don't use my own code. First I would like to get the StreamReader code running

                  I load the SampleStreamReader_NT7.zip to NT 7
                  load the SampleStreamReader as an Indicator into an Apple chart
                  and watch the Output window, which remains empty in any case

                  File Format is

                  2015-04-29 11864.4 11885.05 11410.54 11432.72
                  2015-05-01 11864.4 11885.05 11410.54 11432.72
                  2015-05-02 11864.4 11885.05 11410.54 11432.72
                  2015-05-03 11864.4 11885.05 11410.54 11432.72
                  2015-05-04 11864.4 11885.05 11410.54 11432.72
                  2015-05-05 11864.4 11885.05 11410.54 11432.72
                  2015-05-06 11864.4 11885.05 11410.54 11432.72
                  2015-05-07 11864.4 11885.05 11410.54 11432.72

                  Comment


                    #10
                    Hello Atreio,

                    Thank you for your response.

                    Would you mind sending me the file you are testing? You can send it to platformsupport[at]ninjatrader[dot]com with this thread in the subject line if you prefer: "http://www.ninjatrader.com/support/forum/showthread.php?t=73663"

                    Comment


                      #11
                      I tried different versions. I sent you the last one, which contains only very few data.
                      I also attached the script that I used (downloaded from my NT 7 instattation). I did not Change it, so it should correspond to the original file from your link.

                      Thank you for your help.

                      Comment


                        #12
                        I managed to run the script. There had been two problems:

                        1. The Date format should be YYYYMMDD

                        2. The following code lines should be removed, because the original code only reads out the current bar OHLC

                        if (Historical)
                        return;

                        Now I’m trying to figure out how to store the historical data in a variable to create a data series. Maybe you know an easy way how to do this?

                        Comment


                          #13
                          Hello Atreio,

                          Thank you for your response.

                          I will follow up here with an example.

                          Comment


                            #14
                            Maybe I can narrow the problem down.

                            I can read the data from the text file (to the output box) and I can define a DataSeries object.

                            What I do not understand is:

                            How do I load the data read from the text file into my DataSeries? I tried this:

                            Indicator = double.Parse(s); s = text string with the Indicator value

                            myDataSeries.Set(Indicator);

                            Pot0.Set(myDataSeries[0]);

                            but myDataSeries does not keep a series of data, instead overwrites the Indicator variable with every loop and always contains only the last Indicator value read from the text file

                            And if this is solved, I might encounter another problem:
                            How do I synchronize the date of my Indicator with the daily bars in the chart?

                            Comment


                              #15
                              Hello,

                              If you are reading the data all at once, you are likely setting the value to the most recent position in the data series.

                              Because DataSeries are synced, each OnBarUpdate is generally needed to produce a entire series instead of just setting the most recent index location. The only way I could think you may be able to get this synced would be if you set a specific number of bars in the DataSeries window when you set up the chart. But once you hit realtime, you have shifted your data and unless you read in new data for each new bar that is generated or it will have a gap.

                              If you have read all the data, and lets say you have 100 bars loaded on the chart and 100 bars loaded from the file. Once you hit RealTime, you could loop through the data and use the BarsAgo to specify the index you are setting.

                              This is the syntax:
                              Code:
                              Plot0.Set(BarsAgo, Value);
                              or
                              Plot0.Set (1, 20.25);
                              I look forward to being of further assistance.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by nleitman, Yesterday, 11:46 AM
                              14 responses
                              33 views
                              0 likes
                              Last Post nleitman  
                              Started by MSerag, Yesterday, 11:52 PM
                              3 responses
                              23 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by dcriador, Yesterday, 01:43 AM
                              6 responses
                              27 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by James650, Today, 08:25 AM
                              1 response
                              2 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by Rogers101, 05-05-2024, 11:30 AM
                              14 responses
                              40 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X