Implementing Pivot Points and Fractals for Trading Strategy in ProBuilder

11 Jan 2018
0 comment
0 attachment

This code snippet demonstrates how to implement a trading strategy using pivot points and fractals in the ProBuilder language. The strategy identifies potential buy and sell levels based on fractal formations and calculates take profit levels using pivot points.

DEFPARAM Cumulateorders=false // Visualisation des fractales avec flèches
Arrow = 0 // Nombres de bougies constituant la fractale (impair)
// libre à vous de changer ce nombre, qui doit être impair
Ncandles = 4 // Nombres de bougies de chaque côté de la bougie extrême
Nside = (Ncandles) / 2 // Définition de la fractale supérieure
IF high[Nside] >= highest[Ncandles](high) THEN
//Fup = high[Nside]
Arrow = 1
buylevel = high[Nside]
ENDIF
// Définition de la fractale inférieure
IF low[Nside] <= lowest[Ncandles](low) THEN
//Fdown = low[Nside]
Arrow = -1
selllevel = low[Nside]
ENDIF
//compute takeprofit based on pivot points
Ht = DHigh(1)
Bs = DLow(1)
C = DClose(1)
Pivot = (Ht + Bs + C) / 3
Res3 = Res1 + (Ht – Bs)
Res2 = Pivot + Ht – Bs
Res1 = (2 * Pivot) – Bs
Sup1 = (2 * Pivot) – Ht
Sup2 = Pivot – (Ht – Bs)
Sup3 = Sup1 – (Ht – Bs)
if close>pivot then //** above Pivot **
i=1
while i<=3 do
if i=1 then
ifloor=pivot
iceil=res1
if close>ifloor and close<iceil then
break
endif
elsif i=2 then
ifloor=res1
iceil=res2
if close>ifloor and close<iceil then
break
endif
elsif i=3 then
ifloor=res2
iceil=res3
if close>ifloor and close<iceil then
break
endif
endif
i=i+1
wend
elsif close<pivot then //** below Pivot **
i=1
while i<=3 do
if i=1 then
ifloor=sup1
iceil=pivot
if close>ifloor and close<iceil then
break
endif
elsif i=2 then
ifloor=sup2
iceil=sup1
if close>ifloor and close<iceil then
break
endif
elsif i=3 then
ifloor=sup3
iceil=sup2
if close>ifloor and close<iceil then
break
endif
endif
i=i+1
wend
endif
// Tracé des flèches
IF Arrow = 1 and not longonmarket THEN
BUY 1 CONTRACT AT buylevel stop
sell at iceil limit
ENDIF
IF Arrow = -1 and not shortonmarket THEN
SELLSHORT 1 CONTRACT AT selllevel stop
exitshort at ifloor limit
ENDIF
if longonmarket then
sell at iceil limit
endif
if shortonmarket then
exitshort at ifloor limit
endif
graph ifloor coloured(0,200,200)
graph iceil coloured(200,0,0)

Explanation of the Code:

  • The code starts by setting up parameters for fractal visualization and defining the number of candles that constitute a fractal.
  • It then checks for fractal formations to determine buy and sell levels.
  • Pivot points are calculated using the high, low, and close prices of the previous day to determine potential resistance (ceil) and support (floor) levels.
  • The strategy uses a loop to determine which pivot level the current price is between, to set appropriate take profit levels for trades initiated at fractal breakout points.
  • Trading commands are issued based on the identified levels, with graphical representation of floor and ceiling levels for better visualization.

This snippet is a practical example of combining fractals and pivot points in a trading strategy, useful for understanding market entry and exit points in algorithmic trading.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/fractal-systeme/page/2/#post-88943

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 Legend
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
134
strategy
171

Recent Snippets

How to Track Up/Down Cumulative Volume Inside Each Candle (Tick Volume Delta)
indicator
This snippet separates the real-time, intra-candle volume into up-volume and down-volume based on whether the last [...]
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 [...]
Logo Logo
Loading...