Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to calculate indicator value according to current price.

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

    How to calculate indicator value according to current price.

    Hi,

    I know OnBarUpdate() function is only called when bar close. But it could be a little bit too late if a bar takes too long to complete.

    How can I calculate the new indicator value according to current change of market price, such that some decision can be made prior to the completion of the new bar.

    I have some function needs to be done on a per-bar basis. It is Ok to be done when the bar close. How to separate those per-bar-basis function with those responding to the instant market change?

    Many thanks!


    Best Regards
    David

    #2
    If you use CalculateOnBarClose=False you can calculate on a tick-by-tick basis
    inside your OnBarUpdate() handler.

    However,
    Inside your handler, when FirstTickOfBar is true, then you know that this tick
    represents the first tick of a new bar, and therefore a bar close has just occurred.

    Code:
    protected override void OnBarUpdate()
    {
        if (FirstTickOfBar)
        {
           .. per bar basis ..
        }
        else
        {
           .. per tick basis ...
        }
    }

    Comment


      #3
      Hello David,

      bltdavid is correct for real-time data only, not historical.

      FirstTickOfBar is true on the first tick of a new bar (meaning the previous bar just closed) when the scripts is processing real-time data with CalculateOnBarClose false.


      Adding a 1 tick series would allow for historical intra-bar actions as well.


      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post
        bltdavid is correct for real-time data only, not historical.
        Ah yes... thank you, Chelsea.

        Luckily, FirstTickOfBar is always true for every historical bar.

        But yes, I should have said that my comments were for real-time data only.

        My code, however, works correctly for both historical bars and real-time data,
        regardless of the CalculateOnBarClose setting.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        1 response
        10 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        9 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        387 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X