Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access bar high series throuugh button click void without UNHANDLED EXCEPTION

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

    Access bar high series throuugh button click void without UNHANDLED EXCEPTION

    Hi,

    If i build buttons with the code provided in this forum post below, how do I access indexed values of the bar series without producing an unhandled exception when accessing through the button click void?

    For example the following code procuces a "Unhandled Exception : index was out of range etc,,," when the button is clicked. It seems I cant access the bar series through event driven voids.... am i missing something here?

    private void OnBuyButtonClick(object sender, RoutedEventArgs rea)
    {
    Button button = sender as System.Windows.Controls.Button;
    if (button != null)
    {
    Print(button.Name + " Clicked");
    Print("Hiigh 3 Bars ago = "+High[3]);
    }

    }



    #2
    Hello marty087,

    When using out of sync events like a buttons event handler or OnRender, you would instead need to use the Get methods to get price data. One example is GetClose:
    Code:
    double closePrice = Bars.GetClose(barIndex);
    Rather than using a BarsAgo, this uses the specific bar index. If you need to know the index from the current bar, you would likely need to store the CurrentBar from OnBarUpdate to a variable, and then use math to work out the StoredCurrentBar - BarsAgo to equal the Index.




    I look forward to being of further assistance.

    Comment


      #3
      This whole issue has been very confusing for me. I have 10k lines of code riddled with references to High[x] and Low[x] etc. But I was only getting the excpetion sometimes whereas othestimes all worked fine. I was trying to catch why and how it was working sometimes and not others and couldnt make any sense of it. One thing I know for sure is that calling a High[0] directly from a ButtomnClick void will never work.

      Anyway, I changed all my code over to use the bars.get method... all working now. Thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      156 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      90 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      138 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      130 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X