Identifying the Bar Numbers of Highest and Lowest Prices Over a Specific Period in ProBuilder

11 Mar 2020
0 comment
0 attachment

This ProBuilder code snippet is designed to find the bar numbers where the highest and lowest prices occurred within the last 100 bars. It is useful for analyzing price movements in trading data.


Massimo = 0
Minimo = 999999
BarraMinimo = 0
BarraMassimo = 0
FOR i = 0 to 99
    IF high[i] > Massimo THEN
        Massimo = high[i]
        BarraMassimo = i
    ENDIF
    IF low[i] < Minimo THEN
        Minimo = low[i]
        BarraMinimo = i
    ENDIF
NEXT
EventoMassimo = BarIndex - BarraMassimo
EventoMinimo = BarIndex - BarraMinimo

Explanation of the Code:

  • The variables Massimo and Minimo are initialized to 0 and 999999, respectively, to store the maximum and minimum prices found within the loop.
  • BarraMinimo and BarraMassimo are initialized to 0. These will store the bar numbers (indices) where the minimum and maximum prices occur.
  • A FOR loop iterates from 0 to 99, which corresponds to the last 100 bars from the current bar.
  • Within the loop, the IF statements check if the current high or low prices are greater than Massimo or less than Minimo. If true, the respective maximum or minimum values and their bar indices are updated.
  • After the loop, EventoMassimo and EventoMinimo calculate the actual bar numbers relative to the current bar index. This is done by subtracting the bar indices of the maximum and minimum from the current bar index (BarIndex).

This code is particularly useful for traders and analysts who need to pinpoint significant price levels and their occurrences over a defined historical period.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/massimo-o-minimo/#post-84055

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...