• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Collect Close price and compare

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

    Collect Close price and compare

    Hello NT-Community,

    I've started over with NinjaScript programming and have a few questions about an indicator I'm currently on.

    I want to store the close price of every bar of the whole chart and compare them. To compare them, I want to view a timespan of 60 minutes and compare these 60 close prices. If there are 5 close prices who are the same, I want to put out an alert.

    My ideas on that:
    I know how to compare and how to put an alert. But I don't know how I can store data and compare them in different timespans. Can you help me there? Would be glad.

    Thank you very much in advance.
    Max

    #2
    Ok, to compare the close price from minute 1 to minute 60, and then minute 2 to minute 61 I have an idea. But how do I store all the close prices from my chart in an array?

    Comment


      #3
      Originally posted by arroganzmaschine View Post
      Hello NT-Community,

      I've started over with NinjaScript programming and have a few questions about an indicator I'm currently on.

      I want to store the close price of every bar of the whole chart and compare them. To compare them, I want to view a timespan of 60 minutes and compare these 60 close prices. If there are 5 close prices who are the same, I want to put out an alert.

      My ideas on that:
      I know how to compare and how to put an alert. But I don't know how I can store data and compare them in different timespans. Can you help me there? Would be glad.

      Thank you very much in advance.
      Max
      Use a Sorted Dictionary, or a Sorted List.

      ref: https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx
      https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx

      Comment


        #4
        Originally posted by koganam View Post
        Thank you. Can you give me an example? I first thought DataSeries Class can help me. https://ninjatrader.com/support/help...ries_class.htm

        Comment


          #5
          Originally posted by arroganzmaschine View Post
          Thank you. Can you give me an example? I first thought DataSeries Class can help me. https://ninjatrader.com/support/help...ries_class.htm
          The examples are at the linked pages.

          Comment


            #6
            Originally posted by koganam View Post
            The examples are at the linked pages.
            Yes, that is right. But how do I collect the data already in the chart?

            Comment


              #7
              Ok, I think MaximumBarsLookback.Infinite is the solution. I will keep you updated.

              Comment


                #8
                How can I draw multiple horizontal lines through a loop? The tag somehow interrupts me.

                Comment


                  #9
                  Hello arroganzmaschine,

                  Thank you for your posts.

                  For the loop and usign drawing obects you can add the variable used in the loop to the tag. For example:
                  Code:
                  for (int i = 10; i > 0; i--)
                  {
                  DrawHorizontalLine("mytag"+i, 1000, Color.Black);
                  }|
                  For the closes, why not just call Close which is already a DataSeries containing the close prices? Close: http://ninjatrader.com/support/helpGuides/nt7/close.htm
                  Patrick H.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_PatrickH View Post
                    Hello arroganzmaschine,

                    Thank you for your posts.

                    For the loop and usign drawing obects you can add the variable used in the loop to the tag. For example:
                    Code:
                    for (int i = 10; i > 0; i--)
                    {
                    DrawHorizontalLine("mytag"+i, 1000, Color.Black);
                    }|
                    For the closes, why not just call Close which is already a DataSeries containing the close prices? Close: http://ninjatrader.com/support/helpGuides/nt7/close.htm
                    Why does this not work?

                    Code:
                           
                     protected override void OnBarUpdate()
                            {
                    	for(int i=10; i>0;i--)
                                   {
                    		DrawHorizontalLine("tag"+i, Close[i], Color.Blue);
                    	       }
                            }
                    Last edited by arroganzmaschine; 06-13-2016, 11:47 AM.

                    Comment


                      #11
                      Hello arroganzmaschine,

                      Thank you for your response.

                      Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
                      Patrick H.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_PatrickH View Post
                        Hello arroganzmaschine,

                        Thank you for your response.

                        Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
                        This is the error I get in my output window.


                        Error on calling 'OnBarUpdate' method for indicator 'MountGlen' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                        Comment


                          #13
                          Hello arroganzmaschine,

                          Thanks for your reply.

                          The error message is advising you that you are accessing something that does not exist. What is happening is that when the bars are loading into your indicator, you code begins executing on the first bar, bar 0, then loads bar 1, then 2, etc.etc. Your code on the first bar does this:

                          for(int i=10; i>0;i--)
                          {
                          DrawHorizontalLine("tag"+i, Close[i], Color.Blue);
                          }

                          On bar zero would be trying to access Close[10] which is 10 bars ago and there are no bars before zero.

                          To prevent the issue you would delay processing until you have the minimum bars needed. You can use the CurrentBar as this holds the index of the current bar being processed. In the example you would return (not process) until you had 10 bars.

                          if (CurrentBar < 10) return; // return until bar 10

                          for(int i=10; i>0;i--)
                          {
                          DrawHorizontalLine("tag"+i, Close[i], Color.Blue);
                          }

                          Please see: http://ninjatrader.com/support/helpG...currentbar.htm
                          Paul H.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by tvaughan4, 12-13-2019, 10:46 PM
                          2 responses
                          16 views
                          0 likes
                          Last Post tvaughan4  
                          Started by digibob, 12-13-2019, 10:01 PM
                          3 responses
                          12 views
                          0 likes
                          Last Post digibob
                          by digibob
                           
                          Started by ldissinger, Yesterday, 12:55 PM
                          1 response
                          19 views
                          0 likes
                          Last Post ldissinger  
                          Started by pstrusi, Yesterday, 09:06 AM
                          1 response
                          28 views
                          0 likes
                          Last Post marcus2300  
                          Started by vpzdcv, Yesterday, 02:31 AM
                          0 responses
                          13 views
                          0 likes
                          Last Post vpzdcv
                          by vpzdcv
                           
                          Working...
                          X