This ProBuilder script is designed to draw horizontal lines on a trading chart at prices that are rounded to the nearest cent from the last closed price. It also demonstrates the use of loops and conditional drawing in ProBuilder.
defparam drawonlastbaronly=true
start = round(close[1]*100)/100 //start price
step = 0.01 //price step
quantity = 2 //lines quantity
i = start
while i < start+(step*quantity) do
drawhline(i) coloured(0,0,0,90)
i=i+step
wend
while i > start-(step*quantity) do
drawhline(i) coloured(0,0,0,90)
i=i-step
wend
return start
Explanation of the Code:
- defparam drawonlastbaronly=true: This line ensures that the drawing commands are executed only on the last bar of the chart, which helps in reducing clutter and improving performance.
- start = round(close[1]*100)/100: This calculates the starting price for the horizontal lines. It rounds the previous bar’s closing price to the nearest cent.
- step = 0.01: This sets the price increment for each line, which is one cent in this case.
- quantity = 2: This defines the number of lines to be drawn above and below the starting price.
- First while loop: This loop draws lines incrementally above the starting price. It continues until it has drawn the specified number of lines (defined by ‘quantity’).
- Second while loop: Similar to the first, but this loop draws lines below the starting price.
- drawhline(i) coloured(0,0,0,90): This function draws a horizontal line at price ‘i’. The ‘coloured’ function is used to set the color and transparency of the line (here, a semi-transparent black).
- return start: This line outputs the starting price to the screen, which can be useful for debugging or information purposes.
This script is useful for traders who want to visualize key price levels that are neatly rounded, aiding in quick visual assessment of price proximity to these levels on historical data.