Loading…

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

SettingDefaultWhat it does
Symbol listAUDJPY,NZDJPY,AUDNZDComma-separated candidate symbols for the basket
Magic number20263001Magic number identifying this basket's own positions
Min swap points per lot2.0Minimum swap, in points per lot per night, to count a direction as favourable
Risk percent per symbol0.5Percent of equity risked per symbol, sized against its own ATR
Max basket risk percent5.0Hard cap on the sum of all symbols' risk this pass will size to
Atr period14ATR period used for volatility-based sizing
Atr timeframePERIOD_D1Timeframe the ATR is measured on
Rebalance interval hours24Hours between rebalance passes
Slippage pips5Slippage allowance, in pips
Dry runfalsetrue = log intended actions only, never trades
Max retries5Attempts per order action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Risk & Lot Size · ATR · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria