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.
    Kate W.NinjaTrader Customer Service

    Comment


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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by traderqz, Today, 12:06 AM
      10 responses
      18 views
      0 likes
      Last Post traderqz  
      Started by algospoke, 04-17-2024, 06:40 PM
      5 responses
      46 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by arvidvanstaey, Today, 02:19 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Started by mmckinnm, Today, 01:34 PM
      3 responses
      5 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by f.saeidi, Today, 01:32 PM
      2 responses
      9 views
      0 likes
      Last Post f.saeidi  
      Working...
      X