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 rocketman7, Today, 02:12 AM
        0 responses
        3 views
        0 likes
        Last Post rocketman7  
        Started by dustydbayer, Today, 01:59 AM
        0 responses
        1 view
        0 likes
        Last Post dustydbayer  
        Started by inanazsocial, Today, 01:15 AM
        0 responses
        3 views
        0 likes
        Last Post inanazsocial  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Working...
        X