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 RideMe, 04-07-2024, 04:54 PM
      6 responses
      31 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      2 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,281 views
      0 likes
      Last Post Leafcutter  
      Started by WHICKED, Today, 12:45 PM
      2 responses
      19 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Started by Tim-c, Today, 02:10 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X