Loading…

Per Position Profit Sparklines

A single P/L number tells you where a trade is, not how it got there. Two positions both sitting at -$20 can have completely different stories - one has been drifting down steadily since it opened, the other spiked to +$60 and has been giving it back for the last hour. This panel keeps a small rolling sparkline of each open position's floating profit so that shape is visible at a glance, next to the ticket, symbol, side and current P/L. MT4 keeps no historical record of an open order's floating profit over time, so there is nothing to query for "yesterday's" shape - this panel samples every open ticket's profit on its own timer (default every 5 seconds) and keeps a bounded, in-memory rolling window per ticket. The history is necessarily empty the moment a ticket first appears and only grows from there; it never shows profit history from before this indicator was running or before the trade was opened, whichever is later. Each sparkline is drawn from small pixel-anchored rectangle objects rather than price/time chart objects, since a sparkline needs to keep its shape regardless of the chart's price scale or zoom level - the same technique documented in this catalogue's SparklineRenderer library, reimplemented directly here because house style forbids one project including another project's file. Notes and limitations Sparkline history starts empty on attach and is lost if the indicator is removed and re-added, or on a terminal restart - it is a live rolling window, not a saved record. A ticket's row and sparkline disappear once that position closes; nothing is kept for closed trades. Sampling runs on a timer independent of tick arrival, so the sparkline shape reflects wall clock time, not tick density.

Indicator · MT4 · v1.0 · Free

About Per Position Profit Sparklines

Per Position Profit Sparklines is an indicator for MetaTrader 4. It has 12 settings, such as Magic filter, Current symbol only and Max positions. MQL source code included.

Files in the download: PerPositionSparklines.mq4, PerPositionSparklines.txt.

Settings

SettingDefaultWhat it does
Magic filter-1Only show orders with this magic number, -1 = show all
Current symbol onlyfalseRestrict the list to this chart's own symbol
Max positions12Maximum rows shown (also caps memory used for history)
History points30Samples kept per sparkline
Sample secs5Seconds between profit samples
Spark width90Sparkline width, pixels
Spark height14Sparkline height, pixels
Row height18Vertical spacing between rows, pixels
Font size8Row text font size
CornerCORNER_LEFT_UPPERPanel corner
X offset10Horizontal offset, pixels
Y offset20Vertical offset, pixels

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria