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

Writing Bar High and Low to a file

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

    Writing Bar High and Low to a file

    Example.

    Have a chart for ES 03-15 with 60 minute bars.

    I want to output to a file the high and low of every 60 min bar for all the data loaded e.g. I may have selected 60 days when loading the chart.

    I also want to output the date and the time of the bar as displayed in the NT chart.

    I have my computer set to Chicago time and hence I want the data to be Chicago time as displayed in my NT charts.

    I had a look around I cannot find anything to build on.

    Help

    #2
    Hello Skiguy,

    Thank you for your note.

    Please take a look at the reference samples below on writing to a file -
    http://www.ninjatrader.com/support/f...ead.php?t=3477

    http://www.ninjatrader.com/support/f...ead.php?t=3475


    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      Should the time be being output from that code?

      Snipped from the code >>>>>> ToDay(Time[0]

      I am getting multiple bars for the day - tick but not times.

      I cannot figure out how to get the time ATM.

      I tried to add the TimeOfDay property but that did not.

      This is the output:

      20150301 2107 2107.5 2106 2106
      20150301 2106.25 2106.25 2104.25 2104.75
      20150301 2104.5 2106 2104.5 2104.75
      20150301 2104.75 2105.75 2104.5 2105.5
      20150301 2105.5 2105.75 2105.25 2105.5
      20150302 2105.5 2105.75 2105 2105
      20150302 2105 2105.5 2104.75 2105
      20150302 2104.75 2105.5 2104.5 2104.5
      Last edited by skiguy; 03-03-2015, 06:29 PM.

      Comment


        #4
        Think I have it sorted

        Think I have it sorted.

        Need to do some QA on the output.

        Added:

        + Time[0].TimeOfDay


        Comment


          #5
          Issue --- not all data is exported?

          60 min bar example.


          I have tried various things but there seems to be a limitation on how much data is output for each execution i.e. never get right to the end of the most recent data.

          Even after adding a date limitation e.g.
          if (ToDay(Time[0]) > 20150101)

          I get variable results. Test 1 I get 990 rows. Test 2 I get 959 rows.

          Even the 990 row example did not quite get to the very lasts data i.e. it stopped at:

          20150302 15:00:00 2111.5 2115.5 2111 2115.25

          959 row example stopped at:
          20150227 07:00:00 2107.25 2107.75 2106 2107.25
          20150227 08:00:00 2107.25 210

          NB it did not even complete writing the entry.

          Curiously, it has stopped here:
          20150227 08:00:00 2107.25 210 a number of times that I have run the test.

          Same data, same chart, same code.


          When I add
          if (ToDay(Time[0]) > 20150228)

          I do get March data to the very current closed bar.


          Is it possible "big" data extractions get interrupted somehow?

          Comment


            #6
            Skiguy.

            I am not aware of anything with that.

            However, I would like to take a look at your code to get a better idea of what is being done there and potentially testing it on my end.
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              What is your calculate on bar close set to?

              Comment


                #8
                CalculateOnBarClose = true;

                as per the sample provided.

                I did try it with false and it not make a difference.

                Having said that given the "random" results it would be hard to know if it made a difference.

                I would only run this when I did not need the very latest bar so for my purposes I would be happy to use what works reliably.



                What do you suggest is the best setting?
                Last edited by skiguy; 03-04-2015, 11:59 PM.

                Comment


                  #9
                  Thanks.

                  Basically Josh's sample with a column added to the output and date >.

                  Also I tried MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
                  but it did not make a any difference.

                  protectedoverridevoid Initialize()
                  {
                  CalculateOnBarClose =
                  false;
                  MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
                  }
                  ///<summary>
                  /// Called on each bar update event (incoming tick)
                  ///</summary>
                  protectedoverridevoid 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(path);

                  // This is the output of all lines. The output format is as follows: Date Open High Low Close
                  //sw.WriteLine(ToDay(Time[0]) + " " + Open[0] + " " + High[0] + " " + Low[0] + " " + Close[0] + " " + ToDay(Time[0]));
                  if (ToDay(Time[0]) > 20150101)
                  sw.WriteLine(ToDay(Time[
                  0]) + " " + Time[0].TimeOfDay + " " + Open[0] + " " + High[0] + " " + Low[0] + " " + Close[0]);
                  }


                  Comment


                    #10
                    Originally posted by skiguy View Post
                    CalculateOnBarClose = true;

                    as per the sample provided.

                    I did try it with false and it not make a difference.

                    Having said that given the "random" results it would be hard to know if it made a difference.

                    I would only run this when I did not need the very latest bar so for my purposes I would be happy to use what works reliably.



                    What do you suggest is the best setting?

                    Probably neither - but it could be close depending on:

                    What is your Session Template set to? 24x7 or something that closes an hour or more after the real close might work better? I could see issues with 4pm EST close....(RTH)... some sort of ETH should work?

                    Comment


                      #11
                      Originally posted by sledge View Post
                      Probably neither - but it could be close depending on:

                      What is your Session Template set to? 24x7 or something that closes an hour or more after the real close might work better? I could see issues with 4pm EST close....(RTH)... some sort of ETH should work?
                      I am set to ETH

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by jclose, Today, 09:37 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post jclose
                      by jclose
                       
                      Started by WeyldFalcon, 08-07-2020, 06:13 AM
                      10 responses
                      1,413 views
                      0 likes
                      Last Post Traderontheroad  
                      Started by firefoxforum12, Today, 08:53 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post firefoxforum12  
                      Started by stafe, Today, 08:34 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post stafe
                      by stafe
                       
                      Started by sastrades, 01-31-2024, 10:19 PM
                      11 responses
                      169 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Working...
                      X