Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

    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[B][COLOR="Red"]-2[/COLOR][/B] && Historical)
          {
          //Do something
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by lorem, Today, 09:18 AM
          1 response
          4 views
          0 likes
          Last Post lorem
          by lorem
           
          Started by bmartz, Today, 09:30 AM
          0 responses
          3 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by GussJ, 03-04-2020, 03:11 PM
          14 responses
          3,244 views
          0 likes
          Last Post GussJ
          by GussJ
           
          Started by ArkansasClint, Today, 09:28 AM
          0 responses
          0 views
          0 likes
          Last Post ArkansasClint  
          Started by hazylizard, Today, 08:38 AM
          4 responses
          12 views
          0 likes
          Last Post hazylizard  
          Working...
          X