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 usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          603 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          22 views
          0 likes
          Last Post xiinteractive  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          21 views
          0 likes
          Last Post Pattontje  
          Started by flybuzz, 04-21-2024, 04:07 PM
          17 responses
          230 views
          0 likes
          Last Post TradingLoss  
          Working...
          X