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

Indicator checks start of a new trading day

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

    Indicator checks start of a new trading day

    Hi there,

    I'm developing an indicator needs to display something at the beginning of a trading day.

    Followed instructions from this thread: http://ninjatrader.com/support/forum...ad.php?t=71559

    And here is my code

    Code:
    protected override void OnBarUpdate()
    		{
                //Add your custom indicator logic here.
    			if (Time.Count > 2 && Time[0].Date != Time[1].Date)
    			{
    				Log("New day " + Time[0].Date.ToLongTimeString(), LogLevel.Information);
    			}
            }

    I'm testing this while using playback. Nothing got printed into the Log, meanwhile keep getting this error message "Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."


    Please advice if there's anyway I could deal with this? Thank you very much!

    #2
    You need to make sure that Time[1] is valid, i.e., that enough bars exist to get a prior bar's time. For example,
    Code:
    if (CurrentBar < 1) return ;
    before your code.

    Comment


      #3
      Hey tradesmart,

      Thank you so much for your help. It worked perfectly.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by guillembm, Yesterday, 11:25 AM
      2 responses
      9 views
      0 likes
      Last Post guillembm  
      Started by junkone, 04-21-2024, 07:17 AM
      9 responses
      68 views
      0 likes
      Last Post jeronymite  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      4 responses
      20 views
      0 likes
      Last Post trilliantrader  
      Started by mgco4you, Yesterday, 09:46 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by wzgy0920, Yesterday, 09:53 PM
      0 responses
      10 views
      0 likes
      Last Post wzgy0920  
      Working...
      X