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 CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      232 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      150 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      161 views
      1 like
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      243 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      198 views
      0 likes
      Last Post CarlTrading  
      Working...
      X