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, 10: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.

    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.

      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 John Bogui, Today, 06:07 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by SteveAU, Yesterday, 08:35 PM
          1 response
          15 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by nduckste, Today, 02:00 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by watchinggoodman, Today, 05:45 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ChrisSch  
          Started by cummish, Today, 03:40 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jason  
          Working...
          X