Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using both OnBarClose True and False in one indicator

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

    Using both OnBarClose True and False in one indicator

    Here's the question: Is it possible to use OnBarClose=False and OnBarClose=True within a single indicator? I think I had read somewhere in the forum that it is possible, but I cannot find the reference.

    I have an indicator that utilizes multiple time frames. I use CalculateOnBarClose=False in the Initialize section. However, there are sections in this indicator that I would like to run with OnBarClose=True to reduce the workload on the software. I know I could extract the concerned sections and put them into another, second indicator but having them all in one would be easier.

    If it is indeed possible, would you please tell me how to do it or provide me with a reference?​

    sandman

    #2
    Hello sandman,

    Thank you for your post.

    You can use IsFirstTickOfBar to separate some logic to be OnBarClose=true and other logic to be false.



    There is a sample NT7 script here on the forum as well that demonstrates:



    Please let us know if you have any further questions.

    Comment


      #3
      Gaby. I think that's the reference I once saw. Thank you. Allow me one more question.

      The if (FirstTickofBar) refers to the primary data series in which it is being used.

      As I mentioned I am using multiple time frames so is it possible to further refine this by specifying which BarsArray I want it to use. Something similar to an indicator where I can for example say
      EMA(BarsArray[4],20)[0].

      so perhaps something like

      if (FirstTickofBar [4][0])


      Makes a difference if for example the primary data series is 1 Minute means it would update every other minute, and if my BarsArray 4 is 5 Minutes it would update only every 5 minutes (which is what I would want).

      Looking forward to your response.

      sandman

      Comment


        #4
        Hello sandman,

        isFirstTickOfBar is not only referring to the primary data series being used. It indicates if the incoming tick is the first tick of a new bar. Your script is being called for all added data series, so unless you have code preventing it from running on the additional series it will check isFirstTickOfBar for all incoming ticks on all added data series.

        If you wanted to check if isFirstTickOfBar is true only for a particular series, separate the logic out using BarsInProgress checks.



        Code:
        if (BarsInProgress == 0)
        if (isFirstTickOfBar)
        //is first tick of bar true on the primary data series
        
        if (BarsInProgress == 1)
        if (isFirstTickOfBar)
        //is first tick of bar true on the secondary data series

        Comment


          #5
          Gaby. Thanks very much. It's all clear - theoretically. Now I'll need some time to turn it into practice. sandman

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          560 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          325 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X