Finding the Second Lowest Value in a Defined Number of Recent Bars

05 Dec 2021
0 comment
0 attachment

This code snippet demonstrates how to find the second lowest low price from a specified number of recent bars in a trading chart using the ProBuilder programming language.


SecondLow = 999999
LookBack = 5
ll = lowest[LookBack](low)
FOR i = 0 to (LookBack - 1)
    IF low[i] > ll THEN
        SecondLow = min(SecondLow,low[i])
    ENDIF
NEXT

The code snippet provided is used to determine the second lowest value among a recent set of low prices in a trading chart. Here’s a step-by-step explanation:

  • Initialization: The variable SecondLow is initially set to a very high value (999999) to ensure that any lower value found in the data will replace it.
  • Setting LookBack Period: The variable LookBack defines the number of recent bars to consider, set here to 5.
  • Finding the Lowest Low: The function lowest[LookBack](low) calculates the lowest value of the low prices over the last 5 bars and stores it in the variable ll.
  • Loop Through Recent Bars: A loop runs from 0 to one less than the LookBack value (i.e., 0 to 4). It checks each bar’s low price within this range.
  • Conditional Check: Inside the loop, there is a condition to check if the current bar’s low price (low[i]) is greater than the lowest low (ll). If true, it then updates SecondLow to be the minimum of its current value or the current bar’s low price. This ensures that by the end of the loop, SecondLow holds the second lowest value.

This approach is efficient for analyzing price trends over a specific number of recent bars, which can be crucial for making informed trading decisions based on historical data.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/second-lowest-low-from-few-bars/#post-92521

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