Drawing Time-Specific Range Boxes with Midline in ProBuilder

23 May 2022
0 comment
0 attachment

The following ProBuilder code snippet is designed to draw rectangular boxes representing the price range between two specific hours, with a horizontal line marking the midpoint of this range. This can be useful for visualizing price movements during a particular trading session or time period.


timec= time>=000000 and time<080000
if timec then
    hh=max(hh,high)
    ll=min(ll,low)
    if hh<>hh[1] then
        hhbar=barindex
    endif
    if ll<>ll[1] then
        llbar=barindex
    endif
endif
if not timec and timec[1] then
    drawrectangle(hhbar,hh,llbar,ll)
    drawsegment(hhbar,(hh+ll)/2,llbar,(hh+ll)/2)
    //rest
    hh=0
    ll=close*100
endif
return

This code snippet operates by defining a specific time condition and drawing rectangles based on the high and low prices during this period. Here’s a step-by-step breakdown:

  • Time Condition: The variable timec checks if the current time is between 00:00:00 and 08:00:00. This sets the period during which the code will track high and low prices.
  • Tracking Highs and Lows: Within the specified time, the code updates the highest (hh) and lowest (ll) prices encountered. It also records the bar index (time point) when these new highs or lows are observed using hhbar and llbar.
  • Drawing the Rectangle: Once the time condition is no longer met (i.e., the time moves past 08:00:00), the code draws a rectangle from the first bar to the last bar where the new high and low were recorded, using these values as the top and bottom of the rectangle.
  • Midline: A horizontal line is drawn at the midpoint between the high and low values across the same bars, visually splitting the rectangle into two equal parts.
  • Resetting Values: After drawing the rectangle and midline, the high value is reset to 0, and the low value is set to 100 times the closing price, preparing the variables for the next session.

This snippet is particularly useful for analyzing price movements within specific time frames, providing a clear visual representation of high-low ranges and their midpoints.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/range-avec-ligne-des-50/#post-169824

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