Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Comparing date of current bar to fixed date

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

    Comparing date of current bar to fixed date

    This example is from the NT 7 Help Guide.
    The actual example is
    If ( ToDay(Time[0]) > 20080915)
    // Do something

    Somehow the way I used it, I'm getting this error:
    The name 'Today' does not exist in the current context.

    Here's my code:

    protectedoverridevoid OnBarUpdate()
    {
    If ( ToDay(Time[
    0]) > 20080915)
    Print(
    "It works");
    else
    Print("It doesn't work");
    }

    #2
    Your 'if' should not be capitalized, please try the snippet below, it should compile fine -

    Code:
    protectedoverridevoid OnBarUpdate()
    {
    if ( ToDay(Time[0]) > 20080915)
    Print("It works");
    else
    Print("It doesn't work"); 
    }

    Comment


      #3
      I am trying to get strategy to print the ticker and the entry date

      Below is what I have, the ticker works but the entry date doesnt

      Print(Instrument.MasterInstrument.Name + " " + DateTime);

      Comment


        #4
        How / where do you set the + DateTime then in your code?

        Comment


          #5
          I have not set the datetime anywhere, this can be replaced with whatever the correct coding is

          Comment


            #6
            I see, there would be several ways to start coding this. You could directly get the time of the execution in the OnExecution() method - http://www.ninjatrader.com/support/h...iexecution.htm

            If you want to stay in the OnBarUpdate() context and aovid the advanced events driven routines, you could check the bar on which the position reported as not flat for example.

            Comment


              #7
              within the onbarupdate cant you simply have a condition 1 then after the condition if everything is true then print the date of the current bar?

              eg
              //Condition 1
              if .......
              Print date
              Enter Long()

              Comment


                #8
                Sure, you can then just print Time[0] which gives you the timestamp of the current bar. However that is the condition trigger time then and does not need to fall in line with the actual fill / execution time.

                Comment


                  #9
                  Thanks Bertrand this is what I wanted.

                  Ok, I have created a strategy with certain criteria that only does the following:
                  //Condition set 1
                  if (.........)
                  Print(Instrument.MasterInstrument.Name + " " + Time[0]);

                  When can I run this to be able to get the current data selections.
                  For example I tried to run this for ASX stocks at 18.00 hrs today as mkt closed at 16.00 hrs however the new selection weren't listed.

                  When I run this for a period of 1/9/13 to 3/10/13 I get two selection on 1/10/13 and 2/10/13. However when I run this from 15/9/13 - 3/10/13 or any other date close to Oct I don't get any selection. What could be causing this give that the selections are in Oct

                  Comment


                    #10
                    Great, which chart series and CalculateOnBarClose setting were you working with?



                    If the bar would not have closed and CalculateOnBarClose = true, you would only get a processing if the new bar opend and thus the old one would have been closed and triggered the OnBarUpdate().

                    Comment


                      #11
                      Re: question 2
                      The bars that were identified were for the 1/10 and 2/10 so both bars should be closed.
                      Why would they appear when the strategy analyser is run from 1/9 but not after that?

                      Comment


                        #12
                        No, the 2/10 bar is not closed in NT's framework, as the opening tick of the new day hat been seen yet and thus the bar is still open - if you work with CalculateOnBarClose = false with this bar the last seen tick would be processed and thus an OnBarUpdate() seen here for this timestamp.

                        Comment


                          #13
                          Ok, I worked it out.
                          It was because I had the minimum bars required set at 20.

                          If in your code you use an indicator such as ATR(14)
                          Does this mean in the strategy analyser you have to set minimum bars required to 14?

                          Comment


                            #14
                            Glad to hear. There's no hard # to exactly correlate, this property provides you generally with a way to set a # of init bars to pass before OnBarUpdate() is called for the strategy. For indicators per default you will not see the first 20 bars, this would be called the unstable period. It could be overwritten though by setting a lower BarsRequired in code in your Initialize() method.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            633 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            364 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            105 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            567 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            568 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X