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

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
      Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.

      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

                  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, 12:47 PM.

                    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?

                      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 gentlebenthebear, Today, 01:30 AM
                          2 responses
                          13 views
                          0 likes
                          Last Post gentlebenthebear  
                          Started by Kaledus, Today, 01:29 PM
                          2 responses
                          7 views
                          0 likes
                          Last Post Kaledus
                          by Kaledus
                           
                          Started by frankthearm, Yesterday, 09:08 AM
                          13 responses
                          45 views
                          0 likes
                          Last Post frankthearm  
                          Started by PaulMohn, Today, 12:36 PM
                          2 responses
                          16 views
                          0 likes
                          Last Post PaulMohn  
                          Started by Conceptzx, 10-11-2022, 06:38 AM
                          2 responses
                          56 views
                          0 likes
                          Last Post PhillT
                          by PhillT
                           
                          Working...
                          X