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
floor=pivot
ceil=res1
if close>floor and close<ceil then
break
endif
elsif i=2 then
floor=res1
ceil=res2
if close>floor and close<ceil then
break
endif
elsif i=3 then
floor=res2
ceil=res3
if close>floor and close<ceil then
break
endif
endif
i=i+1
wend
elsif close<pivot then //** below Pivot **
i=1
while i<=3 do
if i=1 then
floor=sup1
ceil=pivot
if close>floor and close<ceil then
break
endif
elsif i=2 then
floor=sup2
ceil=sup1
if close>floor and close<ceil then
break
endif
elsif i=3 then
floor=sup3
ceil=sup2
if close>floor and close<ceil 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 ceil limit
ENDIF
IF Arrow = -1 and not shortonmarket THEN
SELLSHORT 1 CONTRACT AT selllevel stop
exitshort at floor limit
ENDIF
if longonmarket then
sell at ceil limit
endif
if shortonmarket then
exitshort at floor limit
endif
graph floor coloured(0,200,200)
graph ceil coloured(200,0,0)
Explanation of the Code:
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.
Check out this related content for more information:
https://www.prorealcode.com/topic/fractal-systeme/page/2/#post-88943
Visit Link