Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate and plot a value every 5 bars

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

    Calculate and plot a value every 5 bars

    Hi,


    I would like to run a simple calculation starting from the market open (5pm in the example of the ES) and repeat this every 5 bars.


    Eg when the market opens, calculate the max value - the min value of the previous 5 bars and plot this value. Repeat this calculation every 5 bars for the remainder of the day.

    I can't work out how to put this into practise - whether it's a 'for' loop or something else.



    Any suggestions would be gratefully received.


    Thanks!

    #2
    Hello ballston,

    Thank you for your post.

    I'd recommend using a counter that you reset every 5 bars. Increment the counter once per bar, starting at 1. When the counter reaches 5, you can use MIN(Low,5)[0] on that bar to get the lowest value of the last 5 bars, and MAX(High, 5)[0] to get the highest value in the last five bars (including the bar you're on). Once you've got those, you can plot those how you wish, then reset the counter to 1 before the next bar.





    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Hi Kate,

      I know how to use the min and max syntax thank you so I'm ok on that front. Can you offer any suggestions for the correct way to code a counter and how to incorporate the market open time to restart the calcs for the day?


      Thanks.
      Ben

      Comment


        #4
        Hello ballston,

        Thank you for your clarification.

        To get the session start time, you can check Bars.IsFirstBarOfSession. This will be based on the session start time in the Trading Hours template you are using. You could also consider setting a time condition to check the time if you want to, for example, use ETH bars but reset on RTH session open.

        I'm attaching a simple example script that plots a continuous line of these values.

        Please let us know if we may be of further assistance to you.
        Attached Files

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        579 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 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
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X