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 frankthearm, Yesterday, 09:08 AM
      14 responses
      47 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by gentlebenthebear, Today, 01:30 AM
      2 responses
      13 views
      0 likes
      Last Post gentlebenthebear  
      Started by Kaledus, Today, 01:29 PM
      3 responses
      9 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by PaulMohn, Today, 12:36 PM
      2 responses
      17 views
      0 likes
      Last Post PaulMohn  
      Started by Conceptzx, 10-11-2022, 06:38 AM
      2 responses
      56 views
      0 likes
      Last Post PhillT
      by PhillT
       
      Working...
      X