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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      603 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      349 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      104 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      560 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      560 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X