plotshape() in MQL5: DRAW_ARROW markers and Wingdings codes
Short answer
plotshape() becomes a DRAW_ARROW buffer that holds low[i] or high[i] on signal bars and EMPTY_VALUE elsewhere. Set the glyph with PLOT_ARROW, a Wingdings code, and move it off the bar with PLOT_ARROW_SHIFT.
plotshape() puts a marker on the bars where a condition is true: a triangle under a bar for a buy signal, a cross above it for a sell. MQL5 has the same idea as a plot type: DRAW_ARROW draws one Wingdings glyph on every bar whose buffer value is not EMPTY_VALUE, at the price the buffer holds. So a plotshape becomes a buffer that is low[i] or high[i] on signal bars and EMPTY_VALUE everywhere else, plus a PLOT_ARROW code for the glyph and a PLOT_ARROW_SHIFT to move it a few pixels off the bar.
What plotshape() computes
plotshape(series, title, style, location, color, offset, text, textcolor, size, display) treats series as a condition: a bool is used directly, a number counts as true when it is neither na nor zero. On a true bar the shape named by style (shape.triangleup, shape.triangledown, shape.circle, shape.xcross, shape.diamond, shape.labelup and so on) is drawn at the location: location.abovebar (default) sits just above the high, location.belowbar just below the low, location.top and location.bottom pin it to the pane edge, and location.absolute uses the numeric value of series as the y coordinate. text prints a short label next to the shape, size scales it, and offset shifts it by whole bars. Like plot(), it counts as one of the script's 64 plot outputs and must be called at global scope.
The MQL5 equivalent
The Pine version marks EMA crossovers with triangles.
//@version=6
indicator("Shape demo", overlay=true)
f = ta.ema(close, 9)
s = ta.ema(close, 21)
up = ta.crossover(f, s)
dn = ta.crossunder(f, s)
plotshape(up, "Buy", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(dn, "Sell", shape.triangledown, location.abovebar, color.red, size=size.small)The MQL5 version keeps two buffers. The glyph is a Wingdings character code set with PLOT_ARROW; PLOT_ARROW_SHIFT is in pixels, positive downwards, so a marker anchored at the low gets a positive shift and one anchored at the high a negative one. The EMAs come from iMA handles so the example stays short.
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_label1 "Buy"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrLimeGreen
#property indicator_width1 2
#property indicator_label2 "Sell"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrRed
#property indicator_width2 2
input int InpFast = 9; // Fast EMA
input int InpSlow = 21; // Slow EMA
double BufBuy[], BufSell[];
int hFast, hSlow;
int OnInit()
{
SetIndexBuffer(0, BufBuy, INDICATOR_DATA);
SetIndexBuffer(1, BufSell, INDICATOR_DATA);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(0, PLOT_ARROW, 233); // Wingdings up arrow (shape.triangleup)
PlotIndexSetInteger(1, PLOT_ARROW, 234); // Wingdings down arrow (shape.triangledown)
PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, 10); // pixels below the low (location.belowbar)
PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, -10); // pixels above the high (location.abovebar)
hFast = iMA(_Symbol, _Period, InpFast, 0, MODE_EMA, PRICE_CLOSE);
hSlow = iMA(_Symbol, _Period, InpSlow, 0, MODE_EMA, PRICE_CLOSE);
return (hFast == INVALID_HANDLE || hSlow == INVALID_HANDLE) ? INIT_FAILED : INIT_SUCCEEDED;
}
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[])
{
if(BarsCalculated(hFast) < rates_total || BarsCalculated(hSlow) < rates_total)
return 0;
static double f[], s[];
if(CopyBuffer(hFast, 0, 0, rates_total, f) < 0 || CopyBuffer(hSlow, 0, 0, rates_total, s) < 0)
return 0;
int start = MathMax(prev_calculated - 1, 1);
for(int i = start; i < rates_total; i++)
{
bool up = f[i] > s[i] && f[i - 1] <= s[i - 1]; // ta.crossover
bool dn = f[i] < s[i] && f[i - 1] >= s[i - 1]; // ta.crossunder
BufBuy[i] = up ? low[i] : EMPTY_VALUE;
BufSell[i] = dn ? high[i] : EMPTY_VALUE;
}
return rates_total;
}Wingdings codes that cover the common Pine shapes:
| Pine shape | PLOT_ARROW | Glyph |
|---|---|---|
shape.triangleup, shape.arrowup | 233 or 241 | Up arrow (233 is the thick one) |
shape.triangledown, shape.arrowdown | 234 or 242 | Down arrow |
shape.circle | 159 or 108 | Small dot, filled circle |
shape.square | 110 | Filled square |
shape.diamond | 116 | Filled diamond |
shape.xcross, shape.cross | 251 | Cross mark |
| check mark (no Pine shape) | 252 | Useful for confirmed signals |
size.tiny to size.huge has no direct property; indicator_widthN (1 to 5) scales the glyph, and that is the closest control. text= cannot be rendered by DRAW_ARROW at all: create an OBJ_TEXT object on the signal bar instead (see the plotchar page for a compiled example).
Where the two differ
| Topic | Pine Script | MQL5 |
|---|---|---|
| Anchor price | Implied by location | You write the price into the buffer: low[i], high[i] or the value itself |
| Vertical gap | Automatic, scales with size | PLOT_ARROW_SHIFT in pixels; constant regardless of zoom |
| location.top / bottom | Pinned to the pane edge | No equivalent for a buffer plot; use a chart object with screen coordinates or anchor at high/low |
| Text | text= drawn with the shape | Separate OBJ_TEXT objects, one per signal bar |
| Colour per bar | Series colour allowed | DRAW_COLOR_ARROW with a colour-index buffer |
| offset | Shifts the marker by bars | PLOT_SHIFT on the plot; the anchor price still comes from the bar the buffer index names |
| Numeric series | Non-zero means true; value used only for location.absolute | You decide: test the condition, store the price |
What the Stratlate converter emits
A plotshape() is lowered to a DRAW_ARROW buffer, not dropped: the buffer is written as cond ? high[i] : EMPTY_VALUE (or low[i] for location.belowbar and location.bottom, the series value for location.absolute), and PLOT_ARROW is set from the shape: 241 for triangleup, arrowup and labelup, 242 for their down counterparts, 251 for cross and xcross, 110 for square and diamond, 159 for circle and anything unknown. A constant colour passed as color= is applied with PLOT_LINE_COLOR; in our test a colour passed positionally was not picked up and the marker kept the default colour. text= is drawn as an OBJ_TEXT on the signal bar by the pine_shape_text runtime helper and the glyph is moved 16 pixels away with PLOT_ARROW_SHIFT; size is ignored. The conversion is graded CLEAN; still compile and check the markers on a chart before you rely on them.
Pitfalls
- Leaving the buffer at zero on non-signal bars.
DRAW_ARROWthen draws a glyph at price 0 on every bar and the chart auto-scales to it. WriteEMPTY_VALUEand setPLOT_EMPTY_VALUEto match. - Using the wrong sign for
PLOT_ARROW_SHIFT. Positive moves the glyph down, so a buy marker anchored at the low needs a positive shift or it overlaps the candle. - Testing the crossover with
i - 1when the loop starts at 0. The first iteration reads index -1 and the indicator stops with an array out of range error; start at 1 orMathMax(prev_calculated - 1, 1). - Assuming Pine's
size.smalland MT5'swidth 1look alike. The glyph sizes differ between the two platforms; pick a width by eye. - Passing
naas the series on some bars and expecting a marker. Both platforms treatnaas false; in MQL5 the equivalent is simply not writing the price.
FAQ
How do I draw the Pine text label next to the marker?
Create an OBJ_TEXT named after the bar time on each signal bar, set OBJPROP_TEXT, colour and OBJPROP_ANCHOR (ANCHOR_LOWER for text above a high, ANCHOR_UPPER below a low), and delete it again if the signal disappears while the bar is still forming.
Can one buffer show two different shapes?
No. A plot has exactly one PLOT_ARROW code. Pine scripts that pass a per-bar shape, or a plotarrow() that is sometimes positive and sometimes negative, need two buffers in MQL5, one per glyph.
Where do I find the Wingdings code for a symbol?
The code is the character's position in the Wingdings font, 32 to 255. The Windows Character Map with the Wingdings font selected shows it, and the codes in the table above cover the shapes plotshape offers.
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