Identifying the Bar Index Before a Specific Date in ProScreener

09 Dec 2023
0 comment
0 attachment

This ProBuilder code snippet is designed to find the bar index immediately before a specified date within a screener. This is particularly useful when you need to analyze historical data up to a certain point in time.


MyBar = 0
FOR i = 0 to 253
    IF date[i] < 20180101 THEN
        MyBar = i - 1
        break
    ENDIF
NEXT
SCREENER [MyBar] (MyBar as "MyBar")

The code snippet provided performs the following operations:

  • Initialization: The variable MyBar is initialized to 0. This variable will store the bar index immediately before the specified date.
  • Loop through bars: A FOR loop iterates from 0 to 253. This range is used because ProScreener has a maximum lookback limit of 254 bars.
  • Condition check: Inside the loop, an IF statement checks if the date at index i is less than 20180101. This date should be adjusted based on the specific analysis requirements.
  • Update MyBar: If the condition is true, MyBar is set to i - 1. This assignment captures the last bar index before the specified date.
  • Exit loop: The break statement immediately exits the loop once the condition is met, optimizing performance by not checking further unnecessary bars.
  • Screener output: Finally, the SCREENER function outputs the value of MyBar. This output can be used to further analyze the data starting from the identified bar index.

This approach ensures that the analysis starts from the correct point in time, especially when dealing with non-trading days or holidays, as it finds the closest trading day before the specified date.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/barindex-determination-in-screeners/#post-81466

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...