DRAWBARCHART
DRAWBARCHART in ProBuilder draws a custom OHLC bar from open, high, low and close values, with an optional COLOURED bar and BORDERCOLOR. Syntax and examples.
Syntax
DRAWBARCHART(open, high, low, close) COLOURED(R, G, B) BORDERCOLOR(R, G, B)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
open | price | required | Opening value, drawn as the left tick of the bar. |
high | price | required | Highest value, the top of the vertical bar. |
low | price | required | Lowest value, the bottom of the vertical bar. |
close | price | required | Closing value, drawn as the right tick of the bar. |
R, G, B (COLOURED) | integer | platform default | Bar colour components, 0 to 255. |
R, G, B (BORDERCOLOR) | integer | platform default | Border colour components, 0 to 255. |
How it works
DRAWBARCHART runs inside a ProBuilder indicator. It draws an OHLC bar, a vertical line from low to high with an open tick on the left and a close tick on the right, from the four values passed in. Those values can be constants, variables or expressions, which makes it a way to render a derived bar series such as a smoothed or averaged bar chart. The bar is drawn on the current bar it is called on, so no bar-index argument is needed.
COLOURED sets the bar colour and BORDERCOLOR sets the outline. When both are omitted the platform default colours apply. It behaves like DRAWCANDLE but produces a bar rather than a candle body.
Examples
Example 1, Smoothed Heikin-Ashi bar chart (Indicator)
// Build averaged Heikin-Ashi bars and colour by direction
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
RETURNThe bar is green when the averaged open sits at or below the averaged close, and red otherwise.
Example 2, A raw bar recoloured (Indicator)
// Redraw the current bar in a fixed colour
DRAWBARCHART(open, high, low, close) COLOURED(0, 120, 255)
RETURNPassing the raw OHLC values reproduces the bar with a chosen colour.
Example 3, Bar from a shifted series (Indicator)
// Draw a bar offset up by a fixed amount for comparison
off = 10 * pointsize
DRAWBARCHART(open + off, high + off, low + off, close + off) COLOURED(200, 200, 0)
RETURNShifting each value by the same offset places a comparison bar above the price.
Common errors and gotchas
- Indicator only.
DRAWBARCHARThas no effect in ProScreener, ProOrder or ProBacktest. Keep it in a ProBuilder indicator. - Argument order. The order is open, high, low, close. Swapping high and low or open and close draws a malformed bar.
- No bar-index argument. The bar is drawn on the bar the call runs on, placed by where in the loop it executes, not by an x coordinate.
- Recursive open needs a guard. Heikin-Ashi style opens reference
HAOpen[1], so gate the block with aBarIndextest to avoid an undefined first value.
Related instructions
DRAWCANDLE, draws a custom candlestick instead of a bar.Open, the opening price source.High, the high price source.Low, the low price source.Close, the closing price source.COLOURED, sets the bar colour.DrawOnLastBarOnly, restricts drawing to the last bar.Average, smooths the OHLC values before drawing.
