Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Close[] / Closes[]

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

    Close[] / Closes[]

    Hello,

    I have a weird issue and was hoping your could shed some light on it. I am sure I am missing something very obvious. I have a function that is called when the user clicks the chart. In that function, it checks Close[0] to get the last quoted price. Weirdly, that quoted price, in this instance (in my testing last few hours on NQ), is always 7537.25, yet the current price is far from that. Around 7566. if I print Close[0] in onbarupdate, I get the correct price. If I do not call that function immediately, but leave it until the next bar, I get the correct price! I have worked around the issue by setting a global variable in OnBarUpdate, i.e. currentPrice = close[0]. This is the only place currentPrice is set.

    In OnBarUpdate

    currentPrice = Close[0];

    In the function, I use the following for debug

    Print(Close[0].ToString() + "-" + currentPrice.ToString());

    But, I get this!

    7537.75-7568

    I'm a bit dumfounded by this. Are there instances where Close[0] will not report valid data for the last price? Perhaps in a new thread? (I am using events attached to the mouse click to trigger the function). Close[0] is OK to be used outside of OnBarUpdate? For clarity, this is a single series nq chart, with indicator set to onPriceUpdate.

    What am I missing?

    Thanks.

    #2
    Hello pjsmith,

    Thank you for your post.

    It sounds as though you are trying to get the current value of Close[0] inside your custom event method. If you need to obtain a value like Close[0] value outside of one of the core data event methods, you can use TriggerCustomEvent() to reliably synchronize the barAgo indexer to the current bar being updated. Please see the example from our help guide below:



    If this does not resolve your inquiry, please provide a reduced example of your indicator and we will be happy to review it.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Thank you Kate - I will give that a try...

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      65 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      41 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      23 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      26 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      52 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X