Calculating Round Number Levels for Forex Trading

22 May 2021
0 comment
0 attachment

This ProBuilder code snippet is designed to calculate round number levels in Forex trading, which are often considered psychological levels that can influence market behavior. The code determines the nearest upper and lower round numbers relative to the current price.

roundnumber = 25
pipclose=close/pipsize
for i = 1 to roundnumber DO
    if (pipclose+i) mod roundnumber = 0 THEN
        pipupper = round(pipclose+i)
        if pipupper mod roundnumber = 1 THEN
            pipupper = pipupper-1
        ENDIF
        break
    ENDIF
NEXT
for i = roundnumber downto 1 DO
    if (pipclose-i) mod roundnumber = 0 THEN
        piplower = round(pipclose-i)
        if piplower mod roundnumber = 1 THEN
            piplower = piplower-1
        ENDIF
        break
    ENDIF
NEXT
upper=pipupper*pipsize
lower=piplower*pipsize
return upper as "upper", lower as "lower"

The code snippet above performs the following steps:

  • Initialization: Sets the roundnumber to 25, which is used as a base for calculating the round number levels. The pipclose variable is calculated by dividing the current close price by pipsize, normalizing the price to ‘pip’ units.
  • Upper Round Number Calculation: A loop runs from 1 to roundnumber. It checks if adding each increment to pipclose results in a number that modulo roundnumber equals zero. If true, it rounds the result and checks if it needs adjustment to ensure it’s a proper round number. The loop breaks once a valid upper round number is found.
  • Lower Round Number Calculation: Another loop runs from roundnumber down to 1. It performs a similar check as the upper calculation but subtracts the increment from pipclose. It also breaks once a valid lower round number is found.
  • Result Assignment: The calculated upper and lower round numbers are then scaled back to the original price units by multiplying them by pipsize. The function returns these values labeled as “upper” and “lower”.

This code is useful for traders who consider psychological price levels in their trading strategies, providing a way to automatically identify these levels based on the current market price.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/indicateur-chiffre-rond-forex/#post-174382

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.
JC_Bywan Master
https://market.prorealcode.com/store/volume-profile-solutions/ - Trading since 2008, using PRT since 2009, PRC forums moderator since 2016, helping out when I can. Using personal algorithmic universal market model (any market, any timeframe, self-adaptating no optimisation required), and volume profile and tape personal tools. Scientific coding skills from past life in aerospace sector, in Computational Fluid Dynamics.
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...