• 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 the last historical bar

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

    determine the last historical bar

    Hello,

    I developed an indicator which takes a long time on every "OnBarUpdate".

    I would like to test it on historical data, but i only want it to run on the last bar (the most current one).

    I can test it on live data with "if (Historical) return;", but as i said i need to test it on historical data of different time frames as well.

    I found the idea of checking "if (Double.IsNaN(Close[-1]))", but i cant get it to work, it just seems to quit when it reaches the last bar, even when it is surrounded by a try/catch block.

    Any ideas?

    Thanks a lot!

    EDIT: for reproducing, this is what i tried last:

    try{
    Print(CurrentBar + " testing " + Close[-1]);
    }catch(Exception e){
    Print ("exception at " + CurrentBar + " " + e.ToString() );
    }
    Last edited by styx2000; 09-18-2013, 11:40 AM.

    #2
    Hello styx2000,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    I will investigate this matter further and follow up with you here shortly.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Hello styx2000,

      Thank you for your post.

      You could use CurrentBar-2 here with Count to look at the last historical bar before the current bar:
      Code:
      if(CurrentBar-2 == Count && Historical)
      {
      //Do something
      }
      For information on Count please visit the following link: http://www.ninjatrader.com/support/h.../nt7/count.htm

      Please let me know if I may be of further assistance.
      Patrick H.NinjaTrader Customer Service

      Comment


        #4
        Perfect, that solves my problem. Thanks a lot for your quick reply!

        Comment


          #5
          Hi,

          I have just needed the same but I thing the itshould be like this:
          Code:
          if(CurrentBar == Count-2 && Historical)
          {
          //Do something
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by webus, Today, 02:03 AM
          0 responses
          7 views
          0 likes
          Last Post webus
          by webus
           
          Started by momchi, Yesterday, 07:12 PM
          1 response
          15 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by DieSlower, Yesterday, 11:02 PM
          0 responses
          5 views
          0 likes
          Last Post DieSlower  
          Started by gujungg, Yesterday, 10:59 PM
          0 responses
          13 views
          0 likes
          Last Post gujungg
          by gujungg
           
          Started by DieSlower, Yesterday, 09:46 PM
          0 responses
          13 views
          0 likes
          Last Post DieSlower  
          Working...
          X