Basket Take Profit Level Solver
A basket take-profit target is a single number that depends on every open position at once, not one symbol. Finding "what price makes the account hit +100" the normal way means dragging a chart's crosshair, checking the Account tab, dragging again - trial and error against a number that moves every tick anyway. This script solves it directly. For every open position it computes that symbol's P/L-per-point sensitivity - how much the combined floating profit changes for a one-unit move in that symbol's price, converted to account currency - then, for each symbol individually, works out the price move that symbol alone would need to close the remaining gap between the account's current combined profit and the chosen target, assuming every other symbol's positions stay exactly where they are. That is the honest framing: it is not "the price everything needs to reach together", it is "the price this one symbol needs to reach if it is the only one that moves". When a symbol's own positions are internally hedged (a long and a short of equal size), its sensitivity is zero and no single price can solve the basket alone from that symbol - the script says so instead of printing a meaningless number. If InpDrawOnOpenCharts is on, each solved level is drawn as a dashed horizontal line on the symbol's own chart, when one happens to be open, so the level is visible without keeping the Experts log open. Notes and limitations - Each solved price assumes only that one symbol moves and every other symbol's positions stay at their current price. It is not a joint solution across all symbols moving together - there is no single such solution in general, since infinitely many combinations of moves reach the same target. - A symbol with internally hedged positions (net sensitivity of zero) has no single-symbol solution; the script reports this rather than dividing by zero or guessing. - Sensitivity conversion to account currency uses whichever pair orientation is currently quoted in Market Watch; if no conversion path exists for a symbol's quote currency, its sensitivity is left unconverted and the resulting level is approximate - the log says so. - Drawn lines are not removed automatically when a position closes; re-run the script (or delete the objects manually) after the book changes. - Read-only with respect to trading: the script never opens, closes or modifies an order. It only computes and draws.
Script · MT4 · v1.0 · Free
About Basket Take Profit Level Solver
Basket Take Profit Level Solver is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Target profit, Magic filter and Include swap commission. MQL source code included.
Files in the download: BasketTakeProfitSolver.mq4, BasketTakeProfitSolver.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Target profit | 100.0 | Combined floating profit target, account currency |
| Magic filter | -1 | Magic number filter for positions considered (-1 = every magic) |
| Include swap commission | false | Include swap+commission in the current combined profit |
| Draw on open charts | true | Draw a horizontal level on any open chart matching a symbol |
| Line color | clrOrange | Colour of the drawn level |
| Object prefix | BTPS_ | Prefix for chart objects, so cleanup never touches anyone else's |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT4 Script · MQL4 Source Code