This ProBuilder code snippet demonstrates how to use a WHILE loop to draw horizontal lines on a chart at fixed intervals of 100 points. The example is particularly useful for visualizing significant levels or grid lines on financial charts.
IF NOT DID THEN
NV = 0
while NV <= 30000 DO
drawhline(NV) coloured("cyan")
NV = NV + 100
wend
ONCE DID = 1
ENDIF
RETURN
The code snippet provided performs the following operations:
IF NOT DID THEN condition checks if the variable DID is false (or not yet set). This ensures that the lines are only drawn once.NV is initialized to 0. This variable will be used to set the y-value of the horizontal lines.NV is less than or equal to 30000. Inside the loop, a horizontal line is drawn at the current value of NV using drawhline(NV) coloured("cyan"). The color cyan is specified for the line.NV is incremented by 100 after each iteration. This increment sets the next level at which a horizontal line will be drawn.NV exceeds 30000, the loop terminates.DID is set to 1 by ONCE DID = 1. This prevents the loop from executing again on subsequent calculations or redraws of the chart.ENDIF and RETURN statements mark the end of the conditional block and the function, respectively.This example is a practical demonstration of controlling flow with loops and conditionals in ProBuilder, useful for tasks requiring repeated actions until a certain condition is met.
Check out this related content for more information:
https://www.prorealcode.com/topic/probleme-niveau-100/#post-195634
Visit Link