Calculating Candlestick Body as a Percentage of Its Total Range

18 Mar 2023
0 comment
0 attachment

This ProBuilder code snippet calculates the body of a candlestick as a percentage of its total range and classifies it based on a specified threshold. The result is used to determine if the body’s percentage is less than or equal to 20%.


level = 20
perc = (abs(close-open)/range)*100
result = 0
if perc <= level then
    result = 1
endif
return result

This code snippet is designed to help users understand how to compute relative sizes within a dataset, in this case, financial candlestick data. Here's a breakdown of how the code works:

  • Variable Initialization: The variable level is set to 20, which acts as the threshold percentage.
  • Percentage Calculation: The variable perc calculates the absolute difference between the close and open prices of a candlestick, divided by its range (high minus low), and then multiplied by 100 to convert it into a percentage.
  • Result Initialization: The variable result is initially set to 0.
  • Conditional Logic: An if statement checks if perc is less than or equal to level. If true, result is set to 1.
  • Output: The result is returned, which will be 1 if the body's percentage is less than or equal to 20%, otherwise 0.

This example is useful for understanding conditional statements and basic arithmetic operations in the ProBuilder language, particularly in the context of analyzing financial data.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/blast-off-indicator/#post-133341

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.
Vonasi Master
V-oyaging ON A S-mall I-ncome
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...