DRAWCANDLE
DRAWCANDLE in ProBuilder draws a custom OHLC candlestick from open, high, low and close values, with optional COLOURED body and BORDERCOLOR. Syntax and examples.
Syntax
DRAWCANDLE(open, high, low, close) COLOURED(R, G, B) BORDERCOLOR(R, G, B)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
open | price | required | Opening value of the candle body. |
high | price | required | Highest value, the top of the upper wick. |
low | price | required | Lowest value, the bottom of the lower wick. |
close | price | required | Closing value of the candle body. |
R, G, B (COLOURED) | integer | platform default | Body fill colour components, 0 to 255. |
R, G, B (BORDERCOLOR) | integer | platform default | Border colour components, 0 to 255. |
How it works
DRAWCANDLE runs inside a ProBuilder indicator. It draws a candlestick at the current bar from the four values passed in, which can be constants, variables or expressions rather than the raw price. This makes it a way to render a derived candle series, such as a smoothed or Heikin-Ashi style candle, on top of or beside the price. The candle is drawn once per bar it is called on, so no bar-index argument is needed.
COLOURED sets the body fill and BORDERCOLOR sets the outline. When both are omitted the platform default colours apply.
Examples
Example 1, Smoothed Heikin-Ashi candles (Indicator)
// Build averaged Heikin-Ashi candles 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
DRAWCANDLE(HAOpen, HAHigh, HALow, HAClose) COLOURED(0, 255, 0)
ELSE
DRAWCANDLE(HAOpen, HAHigh, HALow, HAClose) COLOURED(255, 0, 0)
ENDIF
ENDIF
RETURNThe candle is green when the averaged open sits at or below the averaged close, and red otherwise.
Example 2, A raw candle recoloured (Indicator)
// Redraw the current candle in a fixed colour
DRAWCANDLE(open, high, low, close) COLOURED(0, 120, 255) BORDERCOLOR(0, 0, 0)
RETURNPassing the raw OHLC values reproduces the bar with a chosen fill and border.
Example 3, Candle from a shifted series (Indicator)
// Draw a candle offset up by a fixed amount for comparison
off = 10 * pointsize
DRAWCANDLE(open + off, high + off, low + off, close + off) COLOURED(200, 200, 0)
RETURNShifting each value by the same offset places a comparison candle above the price.
Common errors and gotchas
- Indicator only.
DRAWCANDLEhas 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 candle.
- No bar-index argument. The candle is drawn on the bar the call runs on, so it is 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
DRAWBARCHART, draws a custom OHLC bar instead of a candle.Open, the opening price source.High, the high price source.Low, the low price source.Close, the closing price source.COLOURED, sets the body colour.DrawOnLastBarOnly, restricts drawing to the last bar.Average, smooths the OHLC values before drawing.
