• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error referencing Time[n] in OnMouseUp EventHandler

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

    Error referencing Time[n] in OnMouseUp EventHandler

    I am getting a consistent ArgumentOutOfRange Exception whenever I reference Time[CurrentBar-n] in my OnMouseUp(object sender, MouseEventArgs e) EventHandler. "n" is less than CurrentBar, so it should be within range..

    I don't have any problem working directly with the index numbers directly, but I need to store the values as DateTimes.

    I was able to do this in NT7 without any problems. Is a different approach needed in NT8?
    Last edited by palinuro; 12-12-2015, 09:32 PM.

    #2
    Originally posted by palinuro View Post
    I am getting a consistent ArgumentOutOfRange Exception whenever I reference Time[CurrentBar-n] in my OnMouseUp(object sender, MouseEventArgs e) EventHandler. "n" is less than CurrentBar, so it should be within range..

    I don't have any problem working directly with the index numbers directly, but I need to store the values as DateTimes.

    I was able to do this in NT7 without any problems. Is a different approach needed in NT8?
    There is some rocket science used to ensure that the currentbar is always up to date when using a core event handler like OnBarUpdate/OnMarketData, etc. When you're using a custom method like in your OnMouseUp, the price series array may be unreliable.

    You can either use the absolute index methods like GetTime(idx) which is the recommended way to go, or if you must use Time[idx] for whatever reason - you can try catching up the current bar array yourself, but this is not a documented solution.

    Code:
    		private void onMouseDown(object sender, MouseEventArgs e)
    		{
    			// a very simplified way to sync the current bar
    			for (int i = 0; i < BarsArray.Length; i++)
    			{
    				BarsArray[i].CurrentBar = CurrentBars[i];				
    			}
    						
    			Print(Time[5]);
    		}
    Last edited by NinjaTrader_Matthew; 12-17-2015, 09:06 AM.
    MatthewNinjaTrader Product Management

    Comment


      #3
      thanks Matthew, i switched to GetTime() and it works fine.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by akuntysh, Today, 02:43 AM
      0 responses
      4 views
      0 likes
      Last Post akuntysh  
      Started by thgamey, Today, 02:05 AM
      0 responses
      6 views
      0 likes
      Last Post thgamey
      by thgamey
       
      Started by tpdk2012, Today, 12:51 AM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Started by simonerg, Today, 12:13 AM
      0 responses
      8 views
      0 likes
      Last Post simonerg  
      Started by rickyblah12, 07-20-2019, 01:01 PM
      2 responses
      24 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Working...
      X