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 rexsole, Today, 08:39 AM
      0 responses
      4 views
      0 likes
      Last Post rexsole
      by rexsole
       
      Started by trilliantrader, Yesterday, 03:01 PM
      3 responses
      30 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      4 responses
      26 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Brevo, Today, 01:45 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by rjbtrade1, 11-30-2023, 04:38 PM
      2 responses
      74 views
      0 likes
      Last Post DavidHP
      by DavidHP
       
      Working...
      X