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

Reading file in array

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

    #16
    in the variable region as

    private List<DateTime> dateList = new List<DateTime>();
    private List<int> dayList = new List<int>();

    Comment


      #17
      In this case it might be that you're adding values to the list when you aren't expecting. Each time OnBarUpdate() gets called are you adding to the list? You might want to add some sort of check that prevents this as it sounds like you might be adding on each bar instead of the 7 times you're expecting.

      I won't be able to provide exact answers as I'm not familiar with the entire script you're working on. Do you have a simplified script that replicates the issue I could look at? If the script is basic I can take a look but for more complex debugging please send mail to support at ninjatrader dot com
      LanceNinjaTrader Customer Service

      Comment


        #18
        Attached you will find the script and the .txt to be read.

        Thanks.
        Attached Files

        Comment


          #19
          Thank you for these files. I've tested on my end and it doesn't appear to be an infinite loop even when I uncomment out this code. Please consider decreasing the amount of bars on your chart or reducing the number of times this loop is run. As is you're looping on every new bar which is causing your NinjaTrader to appear to Freeze when it's performing your calculations.
          LanceNinjaTrader Customer Service

          Comment


            #20
            The indicator is addressed for at least 3 or 4 years daily bars. On any bar it has to loop into an external list of date (it depends on market, but not less than 50 dates) and make some calculation. I did it initially with a manual defined array inside the indicator (like array[1] = a, array[2] = b, ..........) and I did not have problems, but I decided it was better to have an external file to read and create the array for easily change the instrument.

            I think that the trouble is in the initial array. The code must create the array on startup and not re-creating/reading it on any bar, because this is a time and resource consuming way.

            So the question is: how can I read the external file only once, create the array and then referring to it through the indicator?

            Thanks.

            Comment


              #21
              Instead of reading from the file in OnStartup consider using a variable to only allow it to run once after all the bars have been loaded.

              Code:
              //inside OBU()
              if(notRead && CurrentBar == Count-1)
              {
                  notRead = false;
                  //perform your file read and create list
              }


              Let me know if I can be of further assistance.
              LanceNinjaTrader Customer Service

              Comment


                #22
                To put it in OnBarUpdate?

                Comment


                  #23
                  Yes, that's likely the approach I would take. There are other ways you could approach it as well, but based on the information I have this sounds like the simplest route.
                  LanceNinjaTrader Customer Service

                  Comment


                    #24
                    I will try it and let you know. Thanks.

                    Comment


                      #25
                      The list is created but how can I move back and forth in the list without using foreach?

                      I transformed the list in array but I'm not sure I can make calculation along the bars.

                      Comment


                        #26
                        I might need some further clarification on your end goals for this script to provide further tips.

                        You can access a specific index of a list by passing the index location you're looking for.

                        myList[LOCATION];
                        LanceNinjaTrader Customer Service

                        Comment


                          #27
                          I need to calculate the difference (in days) between the actual bar Date and a list of dates from an external file.
                          My thought is to create a List to be read, then step into the chart. On each bar I should have as many difference (in days) as the number of dates in my list. As long as time passes I will have negative differences for past dates.

                          When one of the date is found I will plot a vertical bar and the indicator will show the next positive difference.

                          Let's say my dates are 7/25/2013, 8/25/2013, 9/25/2013.

                          on the bar with date 7/26/2013, the indicator would have the following values:

                          7/25/2013 = -1
                          8/25/2013 = 30
                          9/25/2013 = 61

                          I need the indicator to plot on each bar the FIRST positive value in the list (so how many days are left to the next date in the list), so that, in my example, on the following bar 7/27/2013 I will have:

                          7/25/2013 = -2
                          8/25/2013 = 29
                          9/25/2013 = 60

                          the indicator would plot 29.

                          I hope to have better clarified my goal.

                          Thanks.

                          Comment


                            #28
                            Thank you, that does help clarify this.

                            If I were to start going about creating this I would probably try the following first

                            1. Store the text file into a list, I'd use an array if I knew that the text file size wouldn't change, but lists are easier to work with in my opinion.

                            2. On the first bar, determine if this date is > or < the first value in the list. I'd probably do this with a while loop that ends once the list date is greater than the current date. At this point you will want to store the index location of the date in the list

                            3. each new bar compare the list at your index location last found against the current date. Add a logical check that increments the list value once the date is no longer > the current date

                            doing it in this manor would still involve some basic loops but there won't be any reason to continually loop through an entire list each bar.

                            If you require further custom creation of this script please send mail to support at ninjatrader dot com
                            In the subject line type: ATTN Lance and reference this thread.
                            LanceNinjaTrader Customer Service

                            Comment


                              #29
                              Thanks Lance. I will step into your hints and try. In case I will send you a mail.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cre8able, Yesterday, 01:16 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post cre8able  
                              Started by ChartTourist, Today, 08:22 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post ChartTourist  
                              Started by LiamTwine, Today, 08:10 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post LiamTwine  
                              Started by Balage0922, Today, 07:38 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Balage0922  
                              Started by JoMoon2024, Today, 06:56 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post JoMoon2024  
                              Working...
                              X