Prop Guard
- Bibliothèque
-
Shipra Gupta
Je suis Shipra Gupta, trader et développeuse de stratégies quantitatives avec une solide formation en mathématiques, économie et systèmes de trading algorithmique. Au fil des années, j’ai travaillé activement sur les marchés du forex, de l’or, des indices, des matières premières et des - Version: 1.0
PropGuard – Prop-Firm Rule Engine for Any EA
Turn any EA into a prop-firm-safe EA. PropGuard tracks the rules challenge accounts are judged on and stops your strategy before it breaks them.
Features
- Daily loss limit – Balance or max(balance, equity) basis, with your firm's reset hour.
- Max loss modes – Static, end-of-day trailing or intraday trailing, with optional lock at the start balance.
- Safety buffer & warnings – Stop before the limit, not at it. Breach states stay locked for the day or the account.
- Room-aware sizing – PG_SafeLots() caps risk to the room left and respects volume min/max/step/limit and free margin.
- Open-risk aware – PG_CanOpen() adds the stop risk of every open position before allowing a new one.
- Challenge tools – Flatten-all by magic, profit-target detection, trading-day counter, consistency ratio. State survives restarts without files.
Quick start
1. Buy and download the library. MetaTrader installs it to MQL5\Libraries\PropGuard.ex5.
2. Paste the import block below at the top of your EA, indicator or script.
3. Call the functions.
int OnInit() { if(!PG_Init(0,5,10,PG_DD_STATIC,true,10,PG_BASIS_MAXBE,0,0.5,25)) return(INIT_PARAMETERS_INCORRECT); return(INIT_SUCCEEDED); } void OnTick() { if(PG_Update()>=PG_DAILY_BREACH) { PG_CloseAll(-1); return; } double lots=PG_SafeLots(_Symbol,ORDER_TYPE_BUY,ask,sl,0.5,0.5); if(lots>0.0 && PG_CanOpen(risk_money)) trade.Buy(lots,_Symbol,0,sl); }
Import block (copy into your code)
#define PG_OK 0
#define PG_WARN 1
#define PG_DAILY_BREACH 2
#define PG_MAX_BREACH 3
#define PG_TARGET_HIT 4
#define PG_NOT_INIT -1
#define PG_ERR_NONE 0
#define PG_ERR_PARAM 1
#define PG_ERR_NOTINIT 2
#define PG_ERR_SYMBOL 3
#define PG_ERR_CALC 4
#define PG_ERR_MARGIN 5
#define PG_ERR_NOROOM 6
#define PG_ERR_TRADE 7
#define PG_DD_STATIC 0
#define PG_DD_TRAIL_EOD 1
#define PG_DD_TRAIL_INTRA 2
#define PG_BASIS_BALANCE 0
#define PG_BASIS_MAXBE 1
#import "PropGuard.ex5"
int PG_LastError();
bool PG_Init(const double initial_balance,const double daily_loss_pct,const double max_loss_pct, const int dd_mode,const bool lock_at_initial,const double profit_target_pct, const int daily_basis,const int reset_hour_server,const double safety_buffer_pct, const double warn_room_pct);
void PG_SetMagic(const ulong magic);
int PG_Update();
int PG_Status();
double PG_DailyFloor();
double PG_MaxFloor();
double PG_Room();
double PG_DailyPnL();
bool PG_CanOpen(const double risk_money);
double PG_SafeLots(const string symbol,const ENUM_ORDER_TYPE type,const double entry,const double sl, const double risk_pct,const double room_share);
int PG_CloseAll(const long magic);
int PG_TradingDays(const datetime from);
double PG_ConsistencyRatio(const datetime from);
string PG_StatusName(const int status);
string PG_Report();
void PG_ResetState();
#import
Notes
- Rules differ by firm. Set the inputs to match your firm's published rules.
- Works on hedging and netting accounts, any account currency.
- Close requests are throttled; trade permissions are checked before each request.
Technical
- Pure MQL5. No DLL, no WebRequest, no file I/O.
- Every exported function validates its inputs. PG_LastError() returns the reason for any failed call.
- Works in the Strategy Tester and live, on any broker, symbol and account currency.
Past performance shown in screenshots is from historical data and does not guarantee future results.
