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 usasugardefender, Today, 01:42 AM
          0 responses
          1 view
          0 likes
          Last Post usasugardefender  
          Started by haas88, 03-21-2024, 02:22 AM
          15 responses
          182 views
          0 likes
          Last Post haas88
          by haas88
           
          Started by brianfnoel, Today, 01:24 AM
          0 responses
          6 views
          0 likes
          Last Post brianfnoel  
          Started by bill2023, Yesterday, 08:21 AM
          2 responses
          14 views
          0 likes
          Last Post bill2023  
          Started by ynoldsany, Today, 01:00 AM
          0 responses
          3 views
          0 likes
          Last Post ynoldsany  
          Working...
          X