This code snippet demonstrates how to prevent trading orders when the current price is near any pivot points by using arrays in ProBuilder. It is particularly useful for traders who want to avoid entering trades at potentially risky price levels that are close to key support or resistance levels.
DEFPARAM Cumulateorders=false
dist = 5 //distance from pivot points s/r
x = dist*pointsize //find proximity of 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)
//using arrays to store pivot points
$p[0]= Pivot
$p[1] = Res3
$p[2] = Res2
$p[3] = Res1
$p[4] = Sup1
$p[5] = Sup2
$p[6] = Sup3
//loop into the array to check if price is too near
tradeok = 1
for i = 0 to lastset($p)
if abs(close-$p[i])<=x then //near a pivot point
tradeok=0 //no trading allowed!!
break
endif
next
// dummy strategy
if tradeok then
a=rsi[14] crosses over 50
IF a and not longonmarket THEN
BUY 1 CONTRACT AT market
set target pprofit 10
set stop ploss 5
ENDIF
endif
graph tradeok as "no pivot within range"
Explanation of the Code:
$p for easy access.tradeok to 0.tradeok is 1), the script checks for a crossover in the RSI indicator as a condition to enter a trade.This snippet is a practical example of how to integrate technical analysis and conditional logic into trading strategies using ProBuilder.
Check out this related content for more information:
https://www.prorealcode.com/topic/prevent-entry-near-pivot-points/#post-202658
Visit Link