Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Scripts

Closed Trades to CSV - one row per closing deal (partial closes, reversals) - script for MetaTrader 5

Views:
45
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
Exports the closed trades of the account to a CSV file, one row per closing deal.

Why one row per closing deal: a partial close gets its own row with the closed volume. Close-by and netting reversals (one deal that closes a position and opens the opposite one) are split correctly. Each row carries the open time of the position and the volume-weighted open price of the volume that was still open. The entry commission is shared out by closed volume, so profit + commission + swap of all rows adds up to the account result.

Columns: symbol, side, open_time, close_time, volume, open_price, close_price, profit, commission, swap, magic, position_id, duration_sec

Inputs:
From / To: close time range (0 = all history / now). Positions opened before "From" are still exported when they close inside the range.
Symbol: empty = all symbols.
Magic number: -1 = all, 0 = manual trades. The magic is the one of the opening deal.
File name, and an option to save in the common Files folder.

Times are broker server time with seconds (yyyy.mm.dd hh:mm:ss). Money values are in the account currency. Read only: the script does not trade.

Close-by: MetaTrader books the whole profit on one of the two closing deals, so one row shows the profit and the other shows 0.

Tested in the Strategy Tester on a netting account (adding to a position, partial close, reversal) and on a hedging account (partial close, close-by), with magic / symbol / date filters: the exported rows add up to the balance change to the cent.

Codebase

XAUUSD Hourly Volatility Clock: typical range by hour vs today XAUUSD Hourly Volatility Clock: typical range by hour vs today

A 24-hour clock of typical H1 ranges for XAUUSD (and any other symbol) versus the range of the current hour. The profile uses closed hours only. Display only — it does not trade.

Gold Level Map (XAUUSD): Round Numbers, Prior Day/Week Extremes and ADR Gold Level Map (XAUUSD): Round Numbers, Prior Day/Week Extremes and ADR

A clean on-chart map of psychological 00/50 figures, prior day and week extremes, and the average daily range, with honest bounce/break statistics. Display only — it does not trade.

Risk Lot Calculator - lot size from risk percent and stop distance Risk Lot Calculator - lot size from risk percent and stop distance

Small include file that gives you the lot size from risk in percent (or fixed money) and the stop loss distance. Rounds always down, checks min/max lot and free margin.

MACD Signals MACD Signals

Indicator edition for new platform.