Loading…

CSV Column Reorder And Filter

An export written for one purpose rarely matches what the next tool wants. The columns are in the wrong order, the delimiter is a comma when the target locale expects a semicolon, or the date column is in the terminal's own dotted format when the destination wants something an import wizard recognises. Re-running the export with different settings is not always possible once the file already exists and the data that produced it has moved on. This script rewrites the file that already exists instead. Give it a comma separated list of 1-based column numbers in the order you want them - "3,1,2" drops any column past the third and puts what was column three first - choose the input and output delimiter independently, and optionally name one column to reformat from the terminal's native date/time text into ISO 8601 with a space separator. The naive version of a script like this assumes every row has exactly as many columns as the header. A hand-edited or partially corrupted export does not always keep that promise, and a script that reads past the end of a short row silently pulls in the wrong value or crashes. This one checks every row against the columns actually present and skips - rather than mis-writes - any row too short for the requested column order, reporting the count so you know it happened. Notes and limitations - A field the terminal's own StringToTime cannot parse is written through unchanged rather than guessed at - the summary's "left as-is" count tells you how many that was. - InpDateColumnIndex refers to the column's position in the SOURCE file, not its new position after reordering, since that is the column whose raw text is being read. - A row with fewer fields than the highest column number requested is skipped entirely rather than partially written, and counted separately in the summary. - Quoted fields containing the delimiter character are handled by the terminal's own CSV field reader, the same one every other program in this catalogue uses for FILE_CSV mode. - Does not de-duplicate or sort rows - see Duplicate Row Remover for stripping repeated rows from the same kind of export.

Script · MT4 · v1.0 · Free

About CSV Column Reorder And Filter

CSV Column Reorder And Filter is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Input file, Output file and Column order. MQL source code included.

Files in the download: CsvColumnReorderFilter.ex4, CsvColumnReorderFilter.mq4, CsvColumnReorderFilter.txt.

Settings

SettingDefaultWhat it does
Input fileSource CSV file, in MQL4\Files
Output fileDestination CSV filename, in MQL4\Files
Column order1,2,31-based column numbers, comma separated, in the new order
Input delimiterDelimiterCommaDelimiter the source file uses
Output delimiterDelimiterCommaDelimiter to write the destination file with
Has headertrueFirst row is a header, copied through column-reordered too
Date column index01-based column to reformat to ISO 8601 (0 = none)

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria