TradeShield Position Manager Library

Try it before you decide: attach the free demo EA in the Strategy Tester with visual mode on, open a few manual trades and watch the gold TradeShield panel read every basket figure the library returns, tick by tick.

One compiled library that looks after the trades your Expert Advisor has already opened - so your own code can focus on when to enter, not on the dozens of small rules that decide whether a stop change or a close is accepted by the server.

Why it is called TradeShield

Opening a position is one line of code. Protecting it is where most EAs break: a stop moved inside the broker's stops level, a modification sent while the position is frozen, a partial close that leaves a remainder below the minimum lot, a trailing loop that grabs another EA's trades because it only checked the symbol. Each of these is a rejected request in the journal, a failed Market validation, or worse, a live account where two robots fight over the same positions. TradeShield puts a shield between your logic and the trade server: every request is normalised, checked against the symbol's own limits and only then sent, with retries where retrying makes sense.

Magic isolation, built into every call

Every basket function takes the symbol and the magic number as parameters and only reads or touches positions that match both. Run the same EA on EURUSD and XAUUSD with different magics, or three different robots on one symbol, and each one manages strictly its own trades. There is no shared state, no global variables and no files, so nothing leaks between charts.

What is inside - 26 functions in six groups

1. Safety and housekeeping. TS_Version returns the library version for your logs. TS_LastError returns a plain-language result of the last call - "OK", "Buy SL inside stops level", "Remainder would be below minimum", "Close failed, retcode ..." - ready for Print or an on-chart status line. TS_TradeAllowed checks connection, the terminal AutoTrading button, the program's permission, the account's expert-trading flag and the symbol trade mode in one call; every trading function runs it first, so nothing is sent when trading is not allowed.

2. Normalisation. TS_NormalizePrice rounds any price to the symbol's tick size (not only its digits, which matters on indices and metals). TS_NormalizeVolume floors a volume to the volume step, caps it at the maximum and returns 0 when it is below the minimum, so you never send an invalid lot.

3. Basket reading. TS_CountPositions, TS_BasketVolume and TS_BasketProfit (profit plus swap) work on all positions, buys only or sells only. TS_AveragePrice gives the volume-weighted entry of one side. TS_BreakevenPrice gives the price at which that side's basket, swap included, is exactly flat - the level a grid or averaging EA really needs. TS_LockedProfit tells you what the basket is guaranteed to return if every stop loss is hit, and TS_CountProtected how many positions already have their stop at or beyond the entry.

4. Broker limits. TS_StopsLevelPoints and TS_FreezeLevelPoints expose SYMBOL_TRADE_STOPS_LEVEL and SYMBOL_TRADE_FREEZE_LEVEL. TS_StopsLevelOK tells you whether a proposed SL and TP for a buy or a sell are far enough from the current close price. TS_FreezeLevelOK tells you whether a position can be modified or closed right now, or whether its current stop or target is inside the freeze zone.

5. Stop management. TS_ModifySLTP is the safe wrapper the rest of the library is built on: it normalises both prices, returns success without sending anything when nothing would change (no more "no changes" errors), validates the stops and freeze levels, sends the request and retries on requotes, price changes, timeouts and busy servers. TS_MoveToBreakeven moves the stop to entry plus a lock of your choice once a trigger distance is reached, and never moves a stop backwards. TS_TrailFixed trails at a fixed distance in points, starting after a profit threshold and moving only in steps you define, so the server is not flooded on every tick. TS_ATR returns the ATR of the last closed bar safely, and TS_TrailATR trails at ATR times a multiplier, so the stop breathes with volatility.

6. Closing. TS_ClosePosition closes one ticket with the filling mode the symbol supports. TS_PartialClose closes a percentage of a position, floored to the volume step, and refuses cleanly when the part or the remainder would fall below the minimum lot. TS_CloseAll closes every position of a symbol and magic, optionally one side only. TS_CloseBasketAtProfit and TS_CloseBasketAtLoss close the whole basket the moment its result reaches a money target or a money loss limit.

The demo EA and its panel

The screenshots show TradeShieldDemo, a small Expert Advisor included with the library. It is monitor-only: it never opens, modifies or closes a trade. It reads everything through the library and draws it in a compact gold-on-black card in the top-left corner, leaving the right side and the price scale free. Rows: positions per side, volume, basket profit per side and net, average prices, breakeven prices, the breakeven rule with how many positions are already protected, fixed and ATR trailing distances, the broker's stops and freeze levels, and a new Shield Lock row that shows the money already locked in by your current stops. Below it, a short list of the open positions marks each one as NO SL, a stop price, or BE OK. The card measures its own text and shrinks to fit any screen. Its settings: magic number to watch (0 = manual trades), breakeven trigger and lock in points, fixed trailing start and distance, ATR timeframe, period and multiplier, number of position rows, and panel corner, offsets and font size.

How to use it

1. Copy TradeShieldLib.ex5 into your terminal's MQL5\Libraries folder.
2. In your EA add an #import "TradeShieldLib.ex5" ... #import block with the functions you need (signatures below).
3. Call them from OnTick or OnTimer, always with your own symbol and magic, for example:
TS_MoveToBreakeven(_Symbol, Magic, 150, 10);
TS_TrailATR(_Symbol, Magic, PERIOD_H1, 14, 2.0);
if(TS_CloseBasketAtProfit(_Symbol, Magic, -1, 50.0) > 0) Print("basket banked");
if(!TS_ModifySLTP(ticket, sl, tp, 3)) Print(TS_LastError());
4. Compile. No DLL, no file access, no extra resources - and it works on hedging and netting accounts, any symbol and any account currency.

Function signatures

side: -1 = all, 0 = buys, 1 = sells.
string TS_Version()
string TS_LastError()
bool TS_TradeAllowed(string symbol)
double TS_NormalizePrice(string symbol, double price)
double TS_NormalizeVolume(string symbol, double lots)
int TS_CountPositions(string symbol, long magic, int side)
double TS_BasketProfit(string symbol, long magic, int side)
double TS_BasketVolume(string symbol, long magic, int side)
double TS_AveragePrice(string symbol, long magic, int side)
double TS_BreakevenPrice(string symbol, long magic, int side)
double TS_LockedProfit(string symbol, long magic, int side)
int TS_CountProtected(string symbol, long magic, int side)
int TS_StopsLevelPoints(string symbol)
int TS_FreezeLevelPoints(string symbol)
bool TS_StopsLevelOK(string symbol, bool isBuy, double sl, double tp)
bool TS_FreezeLevelOK(ulong ticket)
bool TS_ModifySLTP(ulong ticket, double sl, double tp, int retries)
bool TS_ClosePosition(ulong ticket)
bool TS_PartialClose(ulong ticket, double percent)
int TS_CloseAll(string symbol, long magic, int side)
int TS_CloseBasketAtProfit(string symbol, long magic, int side, double targetMoney)
int TS_CloseBasketAtLoss(string symbol, long magic, int side, double maxLossMoney)
int TS_MoveToBreakeven(string symbol, long magic, int triggerPts, int lockPts)
int TS_TrailFixed(string symbol, long magic, int startPts, int distPts, int stepPts)
double TS_ATR(string symbol, ENUM_TIMEFRAMES tf, int period)
int TS_TrailATR(string symbol, long magic, ENUM_TIMEFRAMES tf, int period, double mult)

Parameter notes

magic - the exact magic number of the positions to manage (0 for manual trades). triggerPts / lockPts - profit in points that arms breakeven, and the points of profit the stop then locks. startPts / distPts / stepPts - profit needed before trailing starts, distance kept behind price, and the minimum move before the stop is updated. mult - ATR multiplier. percent - share of a position to close (100 = all). targetMoney / maxLossMoney - basket profit target and loss limit in account currency, both positive numbers; 0 switches them off. retries - how many times a modification is resent after a requote or timeout.

Honest expectations

TradeShield does not decide when to enter or exit a market - that remains your strategy's job. What it does is make sure that the protective and closing actions your strategy asks for are calculated correctly, respect your broker's limits and stay inside your own magic number. Test it in the Strategy Tester with the demo EA and your own EA on your broker's data before trading live.

If TradeShield saves you development time or keeps your EA out of validation trouble, an honest review on this page would mean a lot - it is the most useful way to tell other developers whether this library is worth adding to their toolbox.

More from author
Simple SMA Cross EA
AL MOOSAWI ABDULLAH JAFFER BAQER
• Please test the product in the Strategy Tester before purchasing to understand how it works. • If you face any issues, contact me via private message—I’m always available to help. • After purchase, send me a screenshot of your order to receive a   FREE EA   as a gift. Welcome to our collection of Expert Advisors! Each EA is available for just $80, a price set to help the entire trading community succeed. My mission is to provide affordable tools that make trading easier and more accessible t
Hope EA MT5
AL MOOSAWI ABDULLAH JAFFER BAQER
• Please test the product in the Strategy Tester before purchasing to understand how it works. • If you face any issues, contact me via private message—I’m always available to help. • After purchase, send me a screenshot of your order to receive a   FREE EA   as a gift.                                       Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to
Happy and Steady
AL MOOSAWI ABDULLAH JAFFER BAQER
Happiness in Forex Means Winning! What if we made your winnings "Steady Winnings!" This will make you happier! (Forex is risky, you may loose all your capital) We implemented a safe and reliable strategy, that proved itself since 2010 until today! It passed COVID 19 fluctuations without any issues! The idea behind the expert to to be a super scalping expert, attacking few pips at a time. This happens while using big lot size, thus insuring handsome profit. Expert entries are very selective, w
Safe and Steady Profits Pro
AL MOOSAWI ABDULLAH JAFFER BAQER
Safety in Forex trading is the main concern of the traders! There is no use to trade today, and loose everything tomorrow! (Trading is risky, and there are no guarantees for winning)   Here comes the power of our expert! The idea behind it is safety to the investors fund, then comes the profit. Thus this expert wont be the expert that will double your account by xx fold. It will be the expert you can rely on for steady, hassle free profits. To do so, the targets pips are minimal to insure
Penny Collector EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Some users are very comfortable keeping their trades for ages, while other users are happy to get the least and leave :) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning)   Check our other products which will be added to the market soon.
Penny Collector Pro
AL MOOSAWI ABDULLAH JAFFER BAQER
5 (1)
Some users are very comfort 2 able keeping their trades for ages, while other users are happy to get the least and leave :) If you cannot wait on your trades, then this expert will be the best for you! The expert tries to enter trades on a high probability of success, and in most cases it do catch the right wave. If not , don't worry because the expert will deal with the situation by itself and will take the trades to profits! (Trading is risky, and there are no guarantees for winning) You
Drag Race Scalper
AL MOOSAWI ABDULLAH JAFFER BAQER
Scalping! What a thrill! Forex trading had been a source of income and thrill at the same time! (Forex is risky, you may loose all your capital) With our new Expert Advisor "Drag Race Scalper" , you will earn both. (Forex is risky, you may loose all your capital) We tried to use a safe, profitable, and fast formula and this is what we ended by! A drag racing scalper! (Forex is risky, you may loose all your capital) In this scalper you would expect few points per trade only. This expert is fo
Against The Surf EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Trading Forex has a million way! One of the innovative ways is to go against the surf! Here we fight the market and work out to get our bread and butter from it :) (Trading is risky, and you may loose!) From here began the idea! Fighting the market. The Expert uses a combination of : Hedging, Grid and trend strategies to operate. This operation allows it to arrive safely even if it worked against the surf! (Trading is risky, and you may loose!) Please find the 99.9% tick data back test res
Cent Collector
AL MOOSAWI ABDULLAH JAFFER BAQER
Cent Collector is the second Expert advisor of the "Collector" Series :) The first was Penny collector :  https://www.mql5.com/en/market/product/61215?source=Site +Profile+Seller And here is the second EA : Cent Collector Those Experts are designed for Scalpers who cannot wait for ages.. As soon as the Expert realizes the profit it cash out and leave. If things went wrong, the Expert will work on managing itself by averaging and will cash out as soon as it could. This version is called Cent
Yen Collector
AL MOOSAWI ABDULLAH JAFFER BAQER
Yen Collector is the Third Expert advisor of the "Collector" Series :) The first was Penny collector :  https://www.mql5.com/en/market/product/61215?source=Site +Profile+Seller The second one was Cent collector:  https://www.mql5.com/en/market/product/65344?source=Site +Profile+Seller And here is the third EA : Yen Collector Those Experts are designed for Scalpers who cannot wait for ages.. As soon as the Expert realizes the profit it cash out and leave. If things went wrong, the Expert will w
Super Hedge Fighter EA
AL MOOSAWI ABDULLAH JAFFER BAQER
5 (1)
• Please test the product in the Strategy Tester before purchasing to understand how it works. • If you face any issues, contact me via private message—I’m always available to help. • After purchase, send me a screenshot of your order to receive a   FREE EA   as a gift. Important Note: Please Adjust the "Distance Between Orders" Setting. Reduce it to achieve optimal results, ideally between 2 and 10. Trading in Forex and volatile markets can be challenging and risky. No strategy will be effect
Market Master EA
AL MOOSAWI ABDULLAH JAFFER BAQER
2.5 (2)
Very Important: Please Adjust the "Distance between orders" .. Lower them to get good results. Higher will make the EA much safer. Trading Forex has a million way! One of the innovative ways is to go against the surf! Here we fight the market and work out to get our bread and butter from it :) (Trading is risky, and you may loose!) From here began the idea! Fighting the market. The Expert uses a combination of : Hedging, Grid and trend strategies to operate. This operation allows it to arr
Magnet Scalper Pro
AL MOOSAWI ABDULLAH JAFFER BAQER
In this EA you will have two sources of income: 1- Direct trades 2- Rebates from your broker. Thus insure to register under an IB that shares with you their revenues Scalping! What a thrill! Forex trading had been a source of income and thrill at the same time! (Forex is risky, you may loose all your capital) With our new Expert Advisor "Magnet Scalper Pro" , you will earn both. (Forex is risky, you may loose all your capital) We tried to use a safe, profitable, and fast formula and this i
Speedy EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Trading using Experts are the best ways to win in Forex! Here are our second Expert Advisor, where you can Set and forget! Time frame: M1 All currency Pairs will work perfectly on the EA Account type: All (If hedging is not allowed, please disable either Sell or Buy) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning)   Check our other pro
Diamond EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Minimum deposit is 1000$ , or 1000 Cent = 10$. (Recommended 1500$) Every 1000$ = 0.01 Lot. Please stick to the rules, as we want you to win, win and win! (Trading is risky, and there are no guarantees for winning)                                         Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell
Impala EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Minimum deposit is 1000$ , or 1000 Cent = 10$. (Recommended 1500$) Every 1000$ = 0.01 Lot. Please stick to the rules, as we want you to win, win and win! (Trading is risky, and there are no guarantees for winning)                                         Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell f
EX Pro EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Fox EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning)
Good Mood Trading EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Hope EA MT4
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Moderate EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
More Pro EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Nu Pro EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Shooting Star EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Tiger EA MT4
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
Treasure EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Time frame: M1                                                 Leverage : Higher the better Spread: Lower the better Account type : All types (EA may enter hedge positions, if you want to disable this feature deactivate either Buy, or Sell from the setting) Please please do not take unnecessary risks. (Trading is risky, and there are no guarantees for winning)   We wish you successful trading. (Trading is risky, and there are no guarantees for winning
LevelGuard Smart SMA EA
AL MOOSAWI ABDULLAH JAFFER BAQER
LevelGuard SmartSMA Master Support & Resistance Trading with Precision LevelGuard SmartSMA leverages the power of moving averages to help you trade confidently across markets. Designed to identify dynamic support and resistance levels, this EA delivers precise trade entries and exits, empowering traders to capitalize on market movements with ease. How It Works Core Strategy: Uses a central SMA (e.g., 50 or 200-period) as a dynamic support or resistance line. Additional SMAs (optional) provide s
Basic SMA Price Cross EA
AL MOOSAWI ABDULLAH JAFFER BAQER
Explore Our Full EA Collection Visit our website for an extensive range of expertly crafted Expert Advisors designed to empower traders of all levels. Whether you're new to trading or a seasoned professional, our tools are tailored to meet your needs. Affordable Trading for Everyone We believe in making trading accessible to everyone. That’s why all our Expert Advisors are priced at just $65 each, helping our community achieve success without breaking the bank. Unlock the Power of Automation Th
Lion’s Roar - Trend Strength Indicator Are you ready to take control of your trading journey? The Lion’s Roar - Trend Strength Indicator is here to help you identify and harness powerful market trends with precision and confidence. Designed with traders in mind, this advanced tool is built on a robust strategy that combines trend direction with momentum validation using the Average True Range (ATR). This indicator is not pre-optimized, giving YOU the freedom to tailor it to your unique trading
Visual Titan Force Indicator MT4
AL MOOSAWI ABDULLAH JAFFER BAQER
Unleash Market Volatility with the Titan Force Indicator! Are you ready to dominate the market by capitalizing on volatility? The Titan Force Indicator is your ultimate trading tool, designed for traders who thrive during periods of heightened market activity. Not Optimized for You – Yet! This indicator is a canvas for your creativity. It's been crafted to let you optimize it according to your unique trading strategies and preferences. Your skills, your edge! How Does the Titan Force Indicator
Filter:
No reviews
Reply to review