Implementing Trade Filters Based on Proximity to Pivot Points Using Arrays in ProBuilder

27 Jun 2018
0 comment
0 attachment

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:

  • Initialization: Disables order cumulation and sets a distance threshold for pivot points.
  • Pivot Point Calculation: Computes daily pivot points and their respective support and resistance levels.
  • Array Storage: Stores the calculated pivot points into an array $p for easy access.
  • Proximity Check: Iterates through the array to check if the current price is within a specified distance from any pivot point. If it is, trading is disabled by setting tradeok to 0.
  • Trading Logic: If the price is not near any pivot point (tradeok is 1), the script checks for a crossover in the RSI indicator as a condition to enter a trade.
  • Graph Output: Displays a graph line indicating whether trading is allowed based on the proximity to pivot points.

This snippet is a practical example of how to integrate technical analysis and conditional logic into trading strategies using ProBuilder.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/prevent-entry-near-pivot-points/#post-202658

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...