• 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

Determine Open > / < Close + $xx.xxx

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

    Determine Open > / < Close + $xx.xxx

    Hello

    I just created a basic indicator but it is not working for some reason.

    In essence, I am just trying to determine if the Open of the current bar is greater or less than the close of the previous bar. But it is not working.

    Once I get this to work, I just want to say, "if it is greater than close of previous bar + x Pips, then plot line"

    It is working fine when I just do, "Open[0] == Close[0]" but it doesn't when I use "Open[0] > Close[1]"

    Here is the code that I am using

    Code:
            protected override void OnBarUpdate()
            {
                Plot0.Set(Open[0] > Close[1] ? 1 : 0);
            }

    #2
    Hello jg123,

    Do you see anything plot on your chart?

    Are there errors on the Log tab of the Control Center? If so, what do these errors report?

    You may be getting a programming error which is causing this not to plot anything.

    If you are getting an Index out of bounds error you may want to add a current bars check.

    For example:

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 1)
    return;

    Plot0.Set(Open[0] > Close[1] ? 1 : 0);
    }

    http://www.ninjatrader.com/support/f...ead.php?t=3170
    JCNinjaTrader Customer Service

    Comment


      #3
      Thank you, JC. That was the problem. I did not manage to place a check to insure that there was enough data.

      I appreciate your help

      Comment


        #4
        After seeing this indicator in action, I would like to make small change to it.

        Instead of saying, "Plot if Close[0] > Open[1]"

        I would like to say

        "if the time on the current candle is more than 10 seconds later than the time on the previous candle, plot something"

        The goal of this is to go through and confirm that there is not missing tick data after having imported a massive amount of data.

        How would I change my criteria to search for the time of the candle instead?

        Comment


          #5
          Hello jg123,

          For something like this you would have to use a some DateTime Functions or a TimeSpan to get the Time of the bars. Note that Time[0] is going to represent the end of a bar so on a 1 Tick chart it is the time of the Tick but on a 1 Minute Bar it is going to be when the bar closed.

          Here is an example that you may view that goes over DateTime Functions.
          http://www.ninjatrader.com/support/f...ad.php?t=19292


          Using a TimeSpan you may do something like:

          protected override void OnBarUpdate()
          {

          if (CurrentBar < 1) return;

          TimeSpan diff = Time[0] - Time[1];

          Print("Difference in seconds : "+diff.Seconds);
          }

          http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx
          JCNinjaTrader Customer Service

          Comment


            #6
            Thanks so much. i will work on that.

            This looks like it will print it on the screen the difference in seconds. What I would prefer is similar to the oscillator that I have now - so basically if the difference in seconds is greater than X then the oscilator would have a value of 1, otherwise it is 0. This way I would be able to quickly see on the chart and zoom way out if there is a discrepancy rather than needing to zoom in so that I can read each print.

            Will what you wrote also provide for the oscillator?

            Comment


              #7
              Hello jg123,

              Yes, it would you would just see if the "diff.Seconds" is > than your threshold and if so then you can set Plot0 to 1 like you were doing previously.
              JCNinjaTrader Customer Service

              Comment


                #8
                Thank you for the response.

                I am definitely not understanding something here (whenever I seem to feel like I am really getting a grasp on writing code, I find out just how elementary I am...*smile*)

                In short, I have written something that is not working.

                Here is my code:

                Code:
                        protected override void OnBarUpdate()
                        {
                
                			if(CurrentBar < 1)
                				return;
                			
                            TimeSpan = Time[0] - Time[1];
                			
                			if(TimeSpan > 10)
                				Plot0 = 1;
                			else
                				Plot0 = 0;
                        }
                There are a gazillion errors associated with this but I can't seem to figure out how to fix them. The error is telling me that TimeSpan is a type and not a variable, but I don't know what I should be doing differently. Also, apparently Plot0 is a read only and so I am not too sure what I need to be doing in order to get this to plot as an oscilator. It worked fine in my previous code that I wrote.

                Could you please help me with how to fix this?

                Thank you!

                Comment


                  #9
                  jg123,

                  TimeSpan would be used as a constructor for your variable. This will define what kind of variable you will be assigning values to it.

                  This is why JC had -
                  Code:
                  TimeSpan diff = Time[0]- Time[1];
                  diff is a TimeSpan variable holding the value from the difference of Time[0] - Time[1]

                  Additionally, you would want to test the diff variable against the value that you want. In this case if the difference was greater than 10 seconds we SET the plot0 to 1
                  Code:
                  if(diff.Seconds > 10)
                   Plot0.Set(1);
                  else
                   Plot0.Set(0);
                  The .Seconds after the diff access's and returns the value in number of seconds from the full value of the variable, since TimeSpan can include dates, minutes and hours.


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

                  Comment


                    #10
                    Okay, that starts to clear things up, I think.

                    Here is what I wrote, basically a copy of what you did if I understand you correctly

                    Code:
                    if(CurrentBar < 1)
                    				return;
                    			
                                TimeSpan = Time[0] - Time[1];
                    			
                    			if(diff.Seconds > 10)
                    				Plot0.Set(1);
                    			else
                    				Plot0.Set(0);
                    With that I get the same error message for TimeSpan and I now get "The name 'diff' does not exist in this context"

                    Comment


                      #11
                      Hello jg123,

                      Thank you for your response.

                      You would need to set the diff as the TimeSpan, please refer to the code below:
                      Code:
                      if(CurrentBar < 1)
                      				return;
                      			
                                  TimeSpan diff = Time[0] - Time[1]; // diff is assigned as a TimeSpan.
                      			
                      			if(diff.Seconds > 10)
                      				Plot0.Set(1);
                      			else
                      				Plot0.Set(0);
                      Patrick H.NinjaTrader Customer Service

                      Comment


                        #12
                        Ah, this is really great. Thank you.

                        Definitely making some progress.

                        Now it appears that there is a bit of my logic that is off.

                        making it > 10 seconds returned a lot of positive values. From there I decided to say > 30 seconds and this is where i start to notice an issue

                        It is correctly identifying if it is greater than 30 seconds form the previous tick - but it does not factor in the minutes.

                        Here are 2 examples to illustrate:

                        Tick Time[1]: 12:34:15
                        Tick Time[0]: 12:34:48

                        This returns a 1 as it should

                        Tick Time[1]: 12:34:15
                        Tick Tim[0]: 13:34:18

                        This returns a 0 even though it is well more than 30 seconds later.

                        It appears that it is only calculating the "seconds" value. I need it to also include the Hours and Minutes in case I am missing several hours (or even days) of data.

                        Could you give some insight on how I would go about adding these details to it?

                        Thanks!

                        Comment


                          #13
                          I figured that I would post a screenshot demonstrating what I am talking about in Post #12.

                          Here you can see that the data on the left of the chart is 1 June and the data after the gap is 16 July - there is definitely more than 30 seconds between the two bits of data and therefore the oscillator should be giving a signal of 1, but, since the second counter is only counting 19 seconds difference between the two pieces of data, it is not showing a value of 1.
                          Attached Files

                          Comment


                            #14
                            Hello jg123,

                            Thank you for your response.

                            I am not seeing the same behavior on my end. Can you provide the full .cs file so I may test this item on my end? The file is located in the (My) Documents\NinjaTrader 7\bin\Custom folder and then the Indicator or Strategy folder respectively.
                            Patrick H.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Patrick

                              Thanks for getting back to me.

                              That is interesting that you are not not getting it. Here is the file. Really looking forward to seeing what you find.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by guvenators, Today, 05:18 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by LANwarr1or, Today, 03:00 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post LANwarr1or  
                              Started by Newtrader101, Today, 02:53 PM
                              2 responses
                              10 views
                              0 likes
                              Last Post Newtrader101  
                              Started by JuanPabloQuevedo, Today, 02:53 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post JuanPabloQuevedo  
                              Started by samir, Today, 03:16 PM
                              2 responses
                              14 views
                              0 likes
                              Last Post samir
                              by samir
                               
                              Working...
                              X