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
33
indicator
132
strategy
171

Recent Snippets

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) [...]
Calculating Break-Even Points in ProBuilder
strategy
This ProBuilder code snippet demonstrates how to calculate the break-even point for a trading position. The break-even [...]
Implementing Time and Day Restrictions in Trading Algorithms
strategy
This code snippet demonstrates how to set restrictions on trading activities based on specific days of the week and [...]
Implementing Partial Position Closure Based on Price Retracement in ProBuilder
strategy
This code snippet demonstrates how to partially close a trading position when the price retraces to a certain level in [...]
Logo Logo
Loading...