The DRAWBARCHART function in ProBuilder language is used to create a custom OHLC (Open, High, Low, Close) bar chart. This function allows users to visually represent these four key data points for financial instruments in a bar chart format, which can be customized with specific colors for both the bars and their borders.
DRAWBARCHART(open, high, low, close) COLOURED(R, G, B) BORDERCOLOR(R, G, B)
The parameters open, high, low, and close represent the values for the open, high, low, and close prices respectively. These can be constants, variables, or expressions. The COLOURED and BORDERCOLOR functions are optional and allow the user to define the color of the bars and their borders using RGB (Red, Green, Blue) values. If these are not specified, the chart will use default colors.
Below is an example of how to use the DRAWBARCHART function to create a smoothed Heiken Ashi bar chart, which is a type of chart used to average price movements for better trend identification:
period = 20
if barindex > period then
avgO = average[period](open)
avgH = average[period](high)
avgL = average[period](low)
avgC = average[period](close)
HAClose = (avgO + avgH + avgL + avgC) / 4
HAOpen = (HAOpen[1] + HAClose[1]) / 2
HAHigh = MAX(avgH, MAX(HAOpen, HAClose))
HALow = MIN(avgL, MIN(HAOpen, HAClose))
if avgO <= avgC then
DRAWBARCHART(HAOpen, HAHigh, HALow, HAClose) COLOURED(0, 255, 0)
else
DRAWBARCHART(HAOpen, HAHigh, HALow, HAClose) COLOURED(255, 0, 0)
endif
endif
return
In this example, the Heiken Ashi values are calculated based on a moving average of the period specified. Depending on whether the average opening price is less than or equal to the average closing price, the bar is colored green (bullish) or red (bearish).