A swap can be a charge or a credit, and the amount depends on the swap mode the broker published for that symbol and on whether tonight is the weekday the broker triples it. This indicator reads the mode and the triple weekday from the symbol's own specification, computes that amount for one night in the deposit currency, and prints a dash and a reason wherever the terminal cannot supply a figure.
What it does
- Draws a table in the chart window with one row per open position, sorted by symbol and then by ticket, in eight columns: symbol, side, volume, swap so far, tonight, normal, nights, horizon.
- The swap so far cell holds the swap the terminal has already recorded on the position, while tonight and normal are computed from the symbol's rates, so the two readings have separate sources.
- Reads the specification of each row's symbol on every redraw, once for a run of equal symbols, so a broker's change reaches the table without a recompile.
- Draws two preview rows for the chart symbol, long side and short side at the example volume, so a book with no open positions still shows what one night costs.
How it works
- LoadSpec reads the swap mode and the two rates with their return flags, and a failure on any of them dashes every figure cell of every row on that symbol and prints SWAP SPEC UNREADABLE once, in the horizon cell; the triple-swap weekday is read on its own, so a failure there keeps the charge and withholds only the multiplier, with TRIPLE - in the header.
- Points mode multiplies the rate by the point, divides by the tick size, then multiplies by the tick value and the volume, which is the one path that already lands in the deposit currency.
- The three currency modes multiply the rate by the volume and mark the cell EST, because the per-volume-unit reading puts an assumption inside the number; a rate in a currency other than the deposit currency prints RAW with the code and is not converted.
- The two interest modes charge price times contract size times volume at rate/100 divided by 360 or 365, on the current price or on the position's open price, and the two reopen modes carry no money amount and print the rate alone.
- Tonight multiplies the unrounded night by the factor and rounds once at display, and it applies only when the server weekday equals the weekday the symbol published; an exact zero and a mode with no money take no suffix.
- The round turn is the spread converted to money through the point, the tick size and the tick value, plus the commission per volume unit from the input, and the horizon is that total divided by the normal night, rounded up after a billionth of a night is subtracted so an exact quotient cannot print one night too many.
Inputs
- Redraw interval, milliseconds (200-5000): how often the table is rebuilt, 1000 by default.
- Triple-swap factor (1-5, 1 disables it): the multiplier used on the weekday the symbol publishes, 3 by default.
- Interest day count (360 or 365): the divisor in the two interest modes, 360 by default; any other value prints one line and falls back to 360.
- Commission per volume unit, both sides (0-100000): added to the spread in the round turn, 0.0 by default.
- Example volume for the two preview rows (0.01-10000): 0.10 by default.
- Position rows drawn (1-20): 8 by default, and the positions above the cap are counted in a +N MORE POSITIONS line.
- Show the two preview rows: on by default.
- Screen corner: lower right by default, and a value that is not a corner falls back to lower right with one log line.
- Inset from the side edge, pixels (0-2000): 10 by default.
- Inset from the top or bottom edge, pixels (0-2000): 10 by default.
- Font size, logical points (6-12): 8 by default, and the column widths scale with it because the grid is measured at 8 points.
How to use it
- Copy the file into MQL5/Indicators in the terminal's data folder, compile it in MetaEditor and attach it to a chart; at the shipped defaults the table sits in the lower-right corner, ten pixels in from each edge on a display scaled to 100 percent, and the distance grows with the display scale, to 15 pixels at 150 percent.
- Type the commission per volume unit if the account is charged one on both sides of a trade; at the default of zero the round turn is the spread alone.
- Read the header before the rows: the second line gives the server time, the deposit currency, the triple weekday and the factor applied tonight, and the third names the swap mode the symbol reports.
Limits
- The horizon is computed from a positive points-mode night only; every other kind of cell refuses it with its own reason, printed in that column.
- The nights column counts server date boundaries between the position's open time and the server clock, so it estimates the charging events while the swap so far cell is the recorded figure.
- There is no order call, no trade header, no history read, no file, no network and no DLL in the file, and no alert, push, sound or email leaves the terminal; it draws chart objects and deletes them on removal.
The table on a chart, cut by the left edge of the picture and drawn with the font size at 7 and the bottom inset at 64: the two preview rows, and the last column carries the round-turn horizon, or the reason it cannot be computed.