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

Check if OnBarUpdate is called because of price change

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

    Check if OnBarUpdate is called because of price change

    I have set Calculate.OnPriceChange because my indicator has to calculate the last bar too.
    However, OnBarUpdate only needs to be called once per bar.
    Is there a proper way to detect if OnBarUpdate is called for a new bar or because of OnPriceChange?
    Or do I have to store the CurrentBar in a private field and check if the CurrentBar has changed?

    #2
    Hello Bobin,

    Thanks for your post.

    Yes, logic can be separated between Calculate.OnPriceChange and Calculate.OnBarClose using IsFirstTickOfBar. Please note that a hosted script will inherit the Calculate mode of the script that hosts it. You can take the following approach to differentiate logic between OnBarClose and OnPriceChange processing.

    Please see this reference sample which demonstrates a technique used for those who need to separate their logic to calculate some values on each tick and others only on the close of a bar. The sample uses Calculate.OnEachTick but this could be changed to OnPriceChange in your script. You will set your host script to Calculate.OnPriceChange and use if(IsFirstTickOfBar) and place all code that needs to calculate once every bar within that condition check. Then place all code that you want to calculate OnPriceChange outside of the IsFirstTickOfBar condition check.

    SampleEnterOnceExitEveryTick -https://ninjatrader.com/support/help...either_cal.htm

    Please let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Brandon

      Comment


        #4
        The link is broken. Could you please repost the link?

        Comment


          #5
          Hello Graci117,

          Here is the link:

          HTML Code:
          https://ninjatrader.com/support/helpGuides/nt8/?separating_logic_to_either_cal.htm
          Gaby V.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Haiasi, 04-25-2024, 06:53 PM
          2 responses
          16 views
          0 likes
          Last Post Massinisa  
          Started by Creamers, Today, 05:32 AM
          0 responses
          4 views
          0 likes
          Last Post Creamers  
          Started by Segwin, 05-07-2018, 02:15 PM
          12 responses
          1,785 views
          0 likes
          Last Post Leafcutter  
          Started by poplagelu, Today, 05:00 AM
          0 responses
          3 views
          0 likes
          Last Post poplagelu  
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,407 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Working...
          X