Identifying the Nearest Fractal Low Relative to a Price Level

21 Jul 2017
0 comment
0 attachment

This ProBuilder code snippet is designed to find the nearest fractal low to a specified price level within a limited number of bars. It utilizes fractal lows to determine potential support levels in trading data.

// settings
priceLevel = 1.17178
FractalPeriod = 3
barLimit = 200

// defining low fractals
cp=FractalPeriod
if low[cp] <= lowest[2*cp+1](low) then LL= -1 else LL=0 endif if LL = -1 then LOL = low[cp] DRAWTEXT("▲",barindex[cp],lol,Dialog,Bold,12) fractal=lol endif // looking for the nearest fractal to priceLevel diff=priceLevel*10 lastfractal=0 lastdiff=0 for i = 0 to barLimit-1 do if fractal[i]>0 and lastFractal<>fractal[i] then
        diff=min(diff,abs(fractal[i]-priceLevel))
        if diff<>lastdiff then
            nearestFractal=fractal[i]
        endif
        lastFractal=fractal[i]
        lastdiff=diff
    endif
next

return nearestFractal,pricelevel coloured(200,200,0)

This code snippet performs the following steps:

  • Setting Parameters: Defines the price level of interest, the period for fractal calculation, and the limit of historical bars to consider.
  • Defining Low Fractals: Identifies fractal lows based on the given fractal period. A fractal low is marked if the low of the current period is the lowest compared to its surrounding bars.
  • Marking Fractals: If a fractal low is identified, it is marked on the chart with a triangle symbol and stored for further comparison.
  • Finding the Nearest Fractal: Iterates through the historical data up to the defined bar limit to find the fractal low closest to the specified price level. This is done by comparing the absolute difference between the fractal low and the price level.
  • Output: Returns the nearest fractal low and the specified price level, highlighting these on the chart with colored lines.

This example is useful for understanding how to implement and utilize fractal-based support levels in trading algorithms using ProBuilder language.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/comparer-valeur-precedente-dans-boucle/#post-146706

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.
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
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...