Carry Harvest Portfolio
A swap-positive carry basket only stays swap-positive as long as the broker's rates stay the same, and brokers change swap rates without warning - a symbol that was paying to hold long can start paying to hold short, or stop paying anything at all. A basket built once and left alone quietly turns into a cost centre the moment that happens, unless something is watching. This reads InpSymbolList and, on each rebalance pass, checks every candidate symbol's current long and short swap rates directly from the broker via MarketInfo(). A symbol whose better side clears the configured minimum gets a position opened in that direction, sized against its own ATR so a single volatile symbol cannot dominate the basket's risk, and capped against a basket-wide risk ceiling so the whole thing cannot grow unbounded. On the next pass, a symbol whose favourable direction has flipped is closed and reopened the other way; a symbol whose swap has gone flat or negative on both sides is closed outright and left empty until it becomes favourable again. MQL4 accounts are always hedging, so this never faces the netting-merge trap an MQL5 twin of the same concept would: a new position on a symbol this basket already holds is never silently blended into the existing one, and every symbol's position is tracked purely by this EA's own magic number, leaving any foreign position on the same symbol untouched. Notes and limitations - Swap rates are read fresh from the broker on every rebalance pass, not cached - a rate that changes between passes is only noticed at the next scheduled rebalance, not immediately. - Sizing uses each symbol's own ATR and the account's own tick value/tick size, never a hardcoded contract size, so it behaves correctly across FX pairs of very different volatility. - No stop-loss is placed on these positions by design - a carry basket's risk control is the volatility-based sizing and the basket-wide risk cap, not a price stop, since a stop would itself frequently interrupt a swap-driven hold. This is a real risk-management choice, not an oversight, and is stated here so it is not mistaken for one. - A symbol unavailable in Market Watch is skipped for that pass rather than failing the whole rebalance. - Existing positions are only opened, closed, or flipped whole - the tool does not resize an already-open position toward a changed target lot size while its favourable direction stays the same.
Expert advisor · MT5 · v1.0 · Free
About Carry Harvest Portfolio
Carry Harvest Portfolio is an expert advisor (trading robot) for MetaTrader 5 based on ATR. It can size trades from your balance and risk percent. It has 12 settings, such as Symbol list, Magic number and Min swap points per lot. MQL source code included.
Files in the download: CarryHarvestPortfolio.ex5, CarryHarvestPortfolio.mq5, CarryHarvestPortfolio.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Symbol list | AUDJPY,NZDJPY,AUDNZD | Comma-separated candidate symbols for the basket |
| Magic number | 20263001 | Magic number identifying this basket's own positions |
| Min swap points per lot | 2.0 | Minimum swap, in points per lot per night, to count a direction as favourable |
| Risk percent per symbol | 0.5 | Percent of equity risked per symbol, sized against its own ATR |
| Max basket risk percent | 5.0 | Hard cap on the sum of all symbols' risk this pass will size to |
| Atr period | 14 | ATR period used for volatility-based sizing |
| Atr timeframe | PERIOD_D1 | Timeframe the ATR is measured on |
| Rebalance interval hours | 24 | Hours between rebalance passes |
| Slippage pips | 5 | Slippage allowance, in pips |
| Dry run | false | true = log intended actions only, never trades |
| Max retries | 5 | Attempts per order action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Risk & Lot Size · ATR · MT5 Expert Advisor · MQL5 Source Code