Loading…

Basket Breakeven Finder

A basket's breakeven price is not its average entry price, and the gap between the two grows every night a position is held. Swap accrues, and any commission was charged whether the trade wins or loses. A grid or martingale basket opened three days ago can have a real breakeven price that is many pips away from what a quick mental average suggests, and finding out by watching the floating total cross zero is a slow way to learn that. This script solves for the exact price directly from the two figures MT4 actually tracks per order - open price and lots for the average, swap plus commission for the drag - rather than approximating. The buy basket and the sell basket on the same symbol are kept separate and never netted together, because a hedged book has two independent baskets with two different breakeven prices, not one blended number that would mean nothing to either side. The result is drawn directly on the chart as a horizontal line, so the level that matters is visible while price moves, not just printed once in a log that scrolls away. Notes and limitations - Assumes the account-currency value of one point stays constant between the average entry price and the breakeven price. Accurate for any basket that has not already moved an extreme distance, which covers essentially every real case. - Pending orders are not part of a basket - only filled market positions contribute. - Swap keeps accruing after the script runs. The line is a snapshot, not a live-updating indicator; re-run it to refresh. - A basket with zero net lots in one direction (no buys, or no sells) simply has no line drawn for that side. - The MQL5 version only runs on a hedging-mode account. On a netting or exchange-margined account it prints and alerts the reason and draws nothing.

Script · MT5 · v1.0 · Free

About Basket Breakeven Finder

Basket Breakeven Finder is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Symbol, Magic filter and Cleanup first. MQL source code included.

Files in the download: BasketBreakevenFinder.ex5, BasketBreakevenFinder.mq5, BasketBreakevenFinder.txt.

Settings

SettingDefaultWhat it does
SymbolSymbol ("" = this chart's symbol)
Magic filter-1Magic number filter (-1 = every magic)
Cleanup firsttrueDelete this script's previous lines first
Color buyclrDodgerBlueLine colour for the buy basket
Color sellclrTomatoLine colour for the sell basket
Label font size8Label font size

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

Download the PDF guide

Tags: Grid · Martingale · Trailing Stop & Break-even · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria