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

StreamWrite & ReadWrite

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

    StreamWrite & ReadWrite

    Hello I have been unsuccessful in correctly modifying the Ninjatrader 7 SampleStreamWriter & SampleReadWrite Files to ALSO allow for recording bar-by-bar data for Indicators where the Data is set at BOTH Calculate on Bar Close = TRUE and FALSE.

    >> BUT in the case where Calculate on Bar Close = FALSE, i want to ONLY write to the file when the bar closes and NOT for every tick by tick.
    >>> IN SUMMARY - the script must allow for writing and saving data for where the selected indicator(s) (ie EMA/SMA/BuySellVolume/etc) are set for BOTH Calculate on Bar Close = True &/or False I would appreciate your help in providing a correctly working MODIFIED SampleStreamWriter & SampleReadWrite files for this purpose. Thanks
    Attached Files

    #2
    Change:

    Code:
            protected override void Initialize()
            {
                CalculateOnBarClose	= true;
            }
    to:

    Code:
            protected override void Initialize()
            {
                CalculateOnBarClose	= false;
            }

    Comment


      #3
      Hello patkum,

      Thank you for your post.

      You could use FirstTickOfBar if CalculateOnBarClose = false to allow for calculations on the end of the bar. For a sample on using FirstTickOfBar and CalculateOnBarClose = false please visit the following link: http://ninjatrader.com/support/forum...ad.php?t=19387

      Please let me know if you have any questions.

      Comment


        #4
        Hi Patrick

        Thanks for the Help reference. However, i would appreciate if you could provide a comprehensive script sample that would allow me to write and save data of any selected indicator(s) (ie EMA/SMA/BuySellVolume/etc) where they are set for BOTH Calculate on Bar Close = True &/or False in the SAME/ONE FILE.

        Thank you

        Comment


          #5
          Hello patkum,

          Thank you for your response.

          We would not provide programming services. You can review and test out the logic in those examples. If you have any specific questions I can point you in the right direction.

          Are you receiving any errors? What is happening that you do not expect? What code have you implemented that you do not see working?

          Comment


            #6
            Originally posted by NinjaTrader_PatrickH View Post
            Hello patkum,

            Thank you for your response.

            We would not provide programming services. You can review and test out the logic in those examples. If you have any specific questions I can point you in the right direction.

            Are you receiving any errors? What is happening that you do not expect? What code have you implemented that you do not see working?
            Hi Patrik

            Thanks. I have tested the Sample StreamWriter for 2 BuySellVolume indicators on the same worksheet-chart where one was set at Calculate on Bar Close=False and the other at Calculate on Bar Close=True. This was done by using the codes BuySellVolume().Values[0][0] for the Buy signal and BuySellVolume().Values[1][0] for the Sell signal.

            I found that the only value written by the StreamWriter for the BuySellVolume is the indicator values set at Calculate on Bar Close=False. I understand that this is the DEFAULT value for the BuySellVolume indicator.

            Now i ALSO want to write the value (in the same StreamWriter script) for this same indicator but where it is set at Calculate on Bar Close=True . For this i tried using a modified code of BuySellVolume(true).Values[0][0]. - BUT this gave me an ERROR.

            I would appreciate your guidance of how i could adjust the StreamWriter script that allows me to ALSO write the vales for the BuySellVolume indicator set at Calculate on Bar Close=True. (ie this would be in addition to the vales for the indicator which is already by default writing the values at Calculate on Bar Close=False).

            Thanks

            Comment


              #7
              Hello patkum,

              Thank you for your response.

              Please attach your script so we may review your implementation of the FirstTicKOfBar concept.

              Comment


                #8
                Originally posted by NinjaTrader_PatrickH View Post
                Hello patkum,

                Thank you for your response.

                Please attach your script so we may review your implementation of the FirstTicKOfBar concept.
                Hi Patrick

                Thanks - here is the script (Test2c)
                Attached Files

                Comment


                  #9
                  Hello patkum,

                  To assist you I have created another example sample stream writer that uses CalculateOnBarClose set to false so that it operates on each tick. I set the output to show the bar data once per bar using the bool FirstTickOfBar, and I output a tick count and the current close price so that you can see how to separate code that executes once per bar and executes on each tick of a bar.

                  Note that the use of CalculateOnbarClose = false will only work on live data as historical data will still be treated as if CalculatedOnbarClose = true. The reason is because historical data is only known as the OHLC data and does not contain all of the ticks that made up the bar. For the purposes of the example I added the statement:

                  if (Historical) return;

                  The above statement will prevent execution until live (or market replay) data is present.

                  Here is a short example of the output:
                  CurrentBar: 2238 Tick# 0 Close Price at each tick: 2056.75
                  CurrentBar: 2238 Tick# 1 Close Price at each tick: 2056.75
                  CurrentBar: 2238 Tick# 2 Close Price at each tick: 2056.75
                  CurrentBar: 2238 Tick# 3 Close Price at each tick: 2056.75
                  CurrentBar: 2238 Tick# 4 Close Price at each tick: 2057
                  CurrentBar: 2238 Tick# 5 Close Price at each tick: 2057
                  CurrentBar: 2238 Tick# 6 Close Price at each tick: 2057
                  CurrentBar: 2238 Tick# 7 Close Price at each tick: 2056.75
                  CurrentBar: 2238 Tick# 8 Close Price at each tick: 2056.75
                  CurrentBar: 2238 Tick# 9 Close Price at each tick: 2056.75
                  CurrentBar: 2238 Tick# 10 Close Price at each tick: 2056.75
                  CurrentBar: 2238 Tick# 11 Close Price at each tick: 2056.75
                  CurrentBar: 2238 Tick# 12 Close Price at each tick: 2056.75
                  BarData when bar completed: 20160524 2056.5 2057 2056.25 2056.75
                  CurrentBar: 2239 Tick# 1 Close Price at each tick: 2056.75
                  CurrentBar: 2239 Tick# 2 Close Price at each tick: 2056.75
                  CurrentBar: 2239 Tick# 3 Close Price at each tick: 2056.75
                  CurrentBar: 2239 Tick# 4 Close Price at each tick: 2056.75
                  CurrentBar: 2239 Tick# 5 Close Price at each tick: 2056.75
                  CurrentBar: 2239 Tick# 6 Close Price at each tick: 2056.75
                  CurrentBar: 2239 Tick# 7 Close Price at each tick: 2056.75

                  Here are references:
                  http://ninjatrader.com/support/helpG...onbarclose.htm
                  http://ninjatrader.com/support/helpG...ttickofbar.htm
                  Attached Files
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Many thanks Paul for this.

                    Kindly help me better understand this script (which is set at {CalculateOnBarClose = false;}

                    So using this script, please confirm the following
                    1) If i want to capture Indicator values on the CURRENT Bar Close then i would use [1] >> eg for EMA Indicators that i have set at Calculate on Bar Close = True on the worksheet/chart, i would code this as EMA(14)[1] in the section of the script shown as
                    // This is the output of all lines. The output format is as follows: Date Open High Low Close sw.WriteLine("BarData when bar completed: "+ToDay(Time[1]) + " " + Open[1] + " " + High[1] + " " + Low[1] + " " + Close[1] + " " + EMA(14)[1] ); tick = 1; // reset tick counter


                    2) However i am not sure with the BuySellVolume Indicator. I understand that this indicator has default setting of Calculate on Bar Close = False. So, kindly clarify what the codes in the script would be for this, where i wish to capture the values on CURRENT BAR CLOSE (ie NOT tick-by-tick), for BOTH:
                    a) The BuySellVolume Indicator where data on the worksheet/chart is set at Calculate on Bar Close = True
                    b) The BuySellVolume Indicator where data on the worksheet/chart is set at Calculate on Bar Close = False

                    I appreciate all your help.

                    Best regards

                    Comment


                      #11
                      Hello patkum,

                      Thanks for your reply.

                      To clarify, when using CalculateOnBarClose = true, the bar Index of [0] refers to the last completed bar and the code is unaware of the currently forming bar until it too has completed. A bar index of [1] would refer to the previous completed bar to the left of the [0] bar.

                      When using CalculateOnBarClose = false the bar index of [0] refers to the currently forming bar on the right edge and is the live data. An index of [1] refers to the last completed bar. Please see the attached for clarity of the indexes when using true or false.

                      With CalculateOnBarClose = false we can use the bool FirstTickOfBar as a condition that is true only once per bar. So when it is true the bar index [0] points to the first tick of the newly forming bar, thus to output the last completed bar data we now have to refer to the index position of [1]. To answer your EMA question, correct you would use EMA(14)[1] in the case of CalculateOnbarClose = false.

                      For the BuySellVolume, in the example I provided using CalculateOnBarClose = false:

                      To output the final bar value (On the FirstTickOfBar)
                      BuySellVolume().Values[0][1] - Previous bar, Sells
                      BuySellVolume().Values[1][1] - Previous Bar, Buys

                      To output the values on each tick
                      BuySellVolume().Values[0][0] - Current tick, Sells
                      BuySellVolume().Values[1][0] - Current tick, Buys
                      ================================================

                      For the BuySellVolume, to output when CalculateOnbarClose = true, use:
                      BuySellVolume().Values[0][0] - last complete bar, Sells
                      BuySellVolume().Values[1][0] - last complete bar, Buys

                      Please note that that the BuySellVolume is a real-time indicator only. It functions only on real-time data and therefore does not plot any values on historical data. Please see: http://ninjatrader.com/support/helpG...sellvolume.htm
                      Attached Files
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Paul

                        Thanks for your guidance/help.

                        I modified the sample script based on what I understood from your writing > but obviously have got something wrong.

                        I have set out the details of the test and error in output in the attached documents.

                        I would deeply appreciate your help in correcting the error and getting the script working properly.

                        Thank again.
                        Attached Files

                        Comment


                          #13
                          Hello patkum,

                          Thanks for your post.

                          I think this will get you closer, you will need to modify for your ema.

                          Code:
                          if (FirstTickOfBar)  // Inthis block of code, the data is written once on the first tick of a new bar
                          				{				
                          					// This is the output of all lines.	The output format is as follows: Date Open High Low Close
                          					sw.WriteLine("BarData when bar completed: "+ToDay(Time[1]) + " " + Open[1] + " " + High[1] + " " + Low[1] + " " + Close[1]+"  sells: "+BuySellVolume().Values[0][1]+ "  Buys" +BuySellVolume().Values[1][1]);
                          					tick = 1;  // reset tick counter
                          				}
                          				
                          				// This is the output on each tick of data
                          				sw.WriteLine("CurrentBar: "+CurrentBar+"  Tick# "+tick+" buys: "+BuySellVolume().Values[0][0]+"  sells: "+BuySellVolume().Values[1][0] );  // on each tick
                          				tick++; // increment tick of bar
                          Paul H.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by xiinteractive, 04-09-2024, 08:08 AM
                          3 responses
                          11 views
                          0 likes
                          Last Post NinjaTrader_Erick  
                          Started by Johnny Santiago, 10-11-2019, 09:21 AM
                          95 responses
                          6,193 views
                          0 likes
                          Last Post xiinteractive  
                          Started by Irukandji, Today, 09:34 AM
                          1 response
                          3 views
                          0 likes
                          Last Post NinjaTrader_Clayton  
                          Started by RubenCazorla, Today, 09:07 AM
                          1 response
                          6 views
                          0 likes
                          Last Post RubenCazorla  
                          Started by TraderBCL, Today, 04:38 AM
                          3 responses
                          26 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X