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 ScottWalsh, Today, 06:52 PM
      3 responses
      18 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      17 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      1 view
      0 likes
      Last Post cre8able  
      Started by Haiasi, Today, 06:53 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by ScottW, Today, 06:09 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X