plotchar() in MQL5: Wingdings glyphs and text on signal bars
Short answer
plotchar() becomes a DRAW_ARROW plot using the closest Wingdings glyph, codes 32 to 255: write the anchor price into the buffer on signal bars. MQL5 has no Unicode marker plot, and an arrow plot cannot show letters, so text= becomes chart text objects.
plotchar() is plotshape() with a character instead of a built-in shape: any single Unicode glyph, drawn above or below the bars where a condition holds, optionally with a short text next to it. MQL5 has no Unicode marker plot. DRAW_ARROW draws one character from the Wingdings font, chosen by its code 32 to 255, so the conversion is: pick the Wingdings glyph closest to the Pine character, write the anchor price into the buffer on signal bars, and render any text= as chart text objects, because an arrow plot cannot show letters.
What plotchar() computes
plotchar(series, title, char, location, color, offset, text, textcolor, size, display) evaluates series as a condition on every bar (a bool, or a number that is true when non-zero and not na). Where it is true, char is drawn at location.abovebar (default), location.belowbar, location.top, location.bottom or, for location.absolute, at the numeric value of series. char must be a single character and is a compile-time constant. text is a constant string drawn beside the glyph; textcolor colours it separately. offset shifts the marker by whole bars; a negative offset is the usual way to mark a pivot on the bar where it actually occurred, several bars after it was confirmed. Each plotchar is one of the script's 64 plot outputs and is called at global scope.
The MQL5 equivalent
The Pine version marks confirmed pivot highs and lows three bars back, with the letters H and L.
//@version=6
indicator("Char demo", overlay=true)
ph = ta.pivothigh(high, 3, 3)
pl = ta.pivotlow(low, 3, 3)
plotchar(not na(ph), "PH", char="▼", location=location.abovebar, color=color.red, offset=-3, text="H")
plotchar(not na(pl), "PL", char="▲", location=location.belowbar, color=color.green, offset=-3, text="L")In MQL5 the glyph is a DRAW_ARROW plot. Rather than shifting the plot with PLOT_SHIFT, the example writes the marker straight into the pivot bar's slot (i - InpRight), which is what the negative offset achieves in Pine and keeps the anchor price correct. The letters are OBJ_TEXT objects named after the bar time, so re-running the loop updates rather than duplicates them.
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_label1 "Pivot high"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrRed
#property indicator_label2 "Pivot low"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrLimeGreen
input int InpLeft = 3; // Left bars
input int InpRight = 3; // Right bars
double BufPH[], BufPL[];
int OnInit()
{
SetIndexBuffer(0, BufPH, INDICATOR_DATA);
SetIndexBuffer(1, BufPL, INDICATOR_DATA);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(0, PLOT_ARROW, 116); // Wingdings diamond (char="◆")
PlotIndexSetInteger(1, PLOT_ARROW, 116);
PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, -12); // above the bar
PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, 12); // below the bar
return INIT_SUCCEEDED;
}
// text="H" / "L": DRAW_ARROW has no letters, so draw a text object on the pivot bar
void MarkText(const string tag, const datetime t, const double price, const string txt,
const color clr, const bool above)
{
string nm = "pv_" + tag + "_" + IntegerToString((long)t);
if(ObjectFind(0, nm) < 0)
ObjectCreate(0, nm, OBJ_TEXT, 0, t, price);
ObjectSetString(0, nm, OBJPROP_TEXT, txt);
ObjectSetInteger(0, nm, OBJPROP_COLOR, clr);
ObjectSetInteger(0, nm, OBJPROP_FONTSIZE, 8);
ObjectSetInteger(0, nm, OBJPROP_ANCHOR, above ? ANCHOR_LOWER : ANCHOR_UPPER);
ObjectSetInteger(0, nm, OBJPROP_SELECTABLE, false);
}
int OnCalculate(const int rates_total, const int prev_calculated,
const datetime &time[], const double &open[], const double &high[],
const double &low[], const double &close[], const long &tick_volume[],
const long &volume[], const int &spread[])
{
int start = MathMax(prev_calculated - 1 - InpRight, InpLeft);
for(int i = start; i < rates_total; i++)
{
BufPH[i] = EMPTY_VALUE;
BufPL[i] = EMPTY_VALUE;
int p = i - InpRight; // the candidate pivot bar; confirmed InpRight bars later
if(p < InpLeft || i < InpRight)
continue;
bool ph = true, pl = true;
for(int k = p - InpLeft; k <= p + InpRight; k++)
{
if(k == p) continue;
if(high[k] >= high[p]) ph = false;
if(low[k] <= low[p]) pl = false;
}
// Pine's plotchar(..., offset=-InpRight) draws on bar p, not on bar i
if(ph) { BufPH[p] = high[p]; MarkText("h", time[p], high[p], "H", clrRed, true); }
if(pl) { BufPL[p] = low[p]; MarkText("l", time[p], low[p], "L", clrLimeGreen, false); }
}
return rates_total;
}
void OnDeinit(const int reason) { ObjectsDeleteAll(0, "pv_"); }Unicode characters that appear in Pine scripts and the Wingdings codes that stand in for them:
| Pine char | PLOT_ARROW | Wingdings glyph |
|---|---|---|
▲ (and ^) | 241 or 233 | Up arrow |
▼ (and v) | 242 or 234 | Down arrow |
| ● • | 159 or 108 | Dot, filled circle |
| ◆ ♦ | 116 | Filled diamond |
| ■ | 110 | Filled square |
| ✕ × x | 251 | Cross mark |
| ✓ | 252 | Check mark |
| ★ | 171 | Star |
Letters and digits cannot be glyphs: the Wingdings font has no alphabet, so plotchar(cond, char="B") needs an OBJ_TEXT on each signal bar, as in the example's MarkText. An OBJ_TEXT holds a single line and should stay short; the documented limit for OBJPROP_TEXT is 63 characters, which is more than any plotchar label needs.
Where the two differ
| Topic | Pine Script | MQL5 |
|---|---|---|
| Character set | Any single Unicode character | Wingdings codes 32 to 255 only |
| Text next to the glyph | text=, rendered with the marker | Separate OBJ_TEXT objects; they are chart objects, not plot data |
| Negative offset | Marker drawn n bars back, anchored to that bar's high or low | Either PLOT_SHIFT with the anchor price taken from i + offset, or write directly into the earlier slot |
| Data Window | Shows the series value | Shows the anchor price (high or low) on signal bars |
| Realtime bar | A pivot confirmed on the live bar may vanish on the next tick | The same; the text object must be removed when the condition clears, or it stays on the chart |
| Cleanup | Automatic when the script is removed | ObjectsDeleteAll(0, prefix) in OnDeinit |
What the Stratlate converter emits
plotchar() is lowered to the same DRAW_ARROW buffer as plotshape(): cond ? high[i] : EMPTY_VALUE (or low[i] for location.belowbar), with PLOT_ARROW chosen from the character: ▲ and ^ give 241, ▼ and v give 242, ● • o give 159, ✕ × x give 251, and any other character falls back to the dot (159). In our test the fallback also happened when the call had a positional title before char=, so the glyph on the chart was a dot rather than a triangle; pass the character as char= without a positional title to get the mapped glyph. text= is drawn by the pine_shape_text runtime helper as an OBJ_TEXT on the bar the marker lands on, and a negative offset is honoured both as PLOT_SHIFT and in the anchor price, which is read from the bar offset bars back. The conversion is graded CLEAN; compile and look at the chart to confirm the glyph you expected.
Pitfalls
- Naming text objects with a counter instead of the bar time. Each recalculation creates a new object on the same bar and the chart slowly fills with duplicates.
- Forgetting to remove the text object when a realtime pivot is invalidated. The buffer value becomes
EMPTY_VALUEand the glyph disappears, but the letter stays. - Using
PLOT_SHIFTfor a negative offset and keepinghigh[i]as the anchor. The marker is drawn three bars back at the wrong bar's high, floating above or below the real pivot. - Expecting
char="B"to show a B.DRAW_ARROWprints Wingdings code 66, which is a hand symbol, not a letter. - Setting
OBJPROP_ANCHORwrong. Text above a high needsANCHOR_LOWER(the text's lower edge sits at the price); the intuitiveANCHOR_UPPERputs it on top of the candle.
FAQ
Can I show the Unicode character itself instead of Wingdings?
Yes, but not through a plot. An OBJ_TEXT with the character as its text, using a font such as Arial, draws any Unicode glyph at a bar and price. You lose the Data Window entry and the ability of other programs to read the buffer, so most conversions use the arrow plot for the marker and text objects only for letters.
Why does the MT5 marker sit a different distance from the bar?
Pine scales the gap with the shape size and chart zoom; MT5's PLOT_ARROW_SHIFT is a fixed number of pixels. Pick a value between 8 and 16 and keep the sign straight: positive moves the glyph down.
Does plotchar with offset repaint?
Only as far as the underlying condition does. A pivot needs right bars of confirmation, so the marker appears right bars late on both platforms and does not move afterwards; writing it into the earlier slot in MQL5 is equivalent to Pine's negative offset, not a look into the future.
Convert the whole script
Paste a Pine Script indicator or strategy and get MQL5 with this and every other call mapped, checked against the original on the same bars, and every construct that could not be carried over reported.
Open the converter