• 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 darkgreen, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post darkgreen  
          Started by GTBrooks, Today, 02:44 PM
          2 responses
          14 views
          0 likes
          Last Post GTBrooks  
          Started by GLFX005, Today, 12:22 PM
          4 responses
          41 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by AspenHiker, Today, 08:37 AM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by MartinT, Yesterday, 01:12 PM
          3 responses
          17 views
          0 likes
          Last Post MartinT
          by MartinT
           
          Working...
          X