Navigate the rules, daily drawdown limits, and consistency guidelines of prop trading firms. Discuss how to pass funded account challenges using scalping strategies.
The solution is utilizing MetaTrader's Terminal Global Variables (GlobalVariableSet and GlobalVariableGet) to write the highest equity value directly to the terminal's physical memory footprint.
The gvName string dynamically appends your account login number. If you run multiple accounts on the same VPS, this prevents cross-contamination of high-water marks. When a breach occurs, GlobalVariableDel(gvName) clears the memory file before ExpertRemove() unloads the EA, ensuring your next 2-to-6 week trading series starts fresh without anchoring to a previous evaluation's peak.
The shift from ORDER_FILLING_FOK (Fill-or-Kill) to ORDER_FILLING_IOC (Immediate-or-Cancel) is critical when operating near failure thresholds. In highly liquid raw spread environments, FOK can result in total order rejection if the requested volume isn't instantly available at the precise microsecond. IOC guarantees the broker will close whatever liquidity is immediately available, incrementally flattening your exposure rather than rejecting the command entirely while equity continues to drop.
Integrating a daily drawdown limit requires the EA to track broker server time for midnight rollovers and calculate two independent failure floors simultaneously. When managing your own deposited capital across a structured 2 to 6-week trading series, the script must evaluate both the series-long trailing floor and the strictly intraday floor, dynamically flattening your exposure if either threshold is breached.
Here is the updated MQL5 implementation utilizing Terminal Global Variables to persist both the daily start-of-day (SOD) equity and the maximum series watermark.
Server Time Rollover (TimeCurrent): The script uses TimeCurrent() rather than TimeLocal() to query the broker's server time. This ensures the daily drawdown baseline resets precisely at broker midnight (typically 00:00 EET on IC Markets) rather than the local system time of your VPS. Using dt.day_of_year cleanly handles month-end and year-end rollovers without complex date math.
The Dual-Floor Logic (MathMax): By calculating MathMax(dynamicTrailingFloor, dynamicDailyFloor), the EA instantly identifies which risk parameter is currently more restrictive. If your account is significantly in profit for the day, the trailing series floor might be the active danger zone. If you take a loss early in the day, the daily floor will sit higher than the trailing floor, triggering the closure first.
To add a take-profit target, you introduce a new input variable for your series equity goal and evaluate it before the drawdown logic inside the OnTick() loop. When your equity crosses this threshold, the script secures the goal, flattens all exposure, wipes the state variables, and unloads itself from the chart so it remains dormant during your rest period between series.
Logic Hierarchy (return; statement): The target goal is intentionally evaluated in step 2, strictly before the drawdown floors are calculated. If the target is hit, the return; command halts the rest of the OnTick() loop. This is critical because flattening multiple positions sequentially takes a few milliseconds; if the code evaluated the drawdown limit simultaneously while spread widens during position closure, it could falsely trigger the failure alert immediately after hitting the win target.
Variable Eradication: By executing GlobalVariableDel() for all three state trackers upon reaching the target, the script ensures that the terminal's memory is totally sanitized. When you initiate a new trading series after your 2 to 4-week break, attaching the EA to the chart will securely initialize fresh baselines without inheriting the previous cycle's data.
Unlike MQL5, which reads the live broker account equity natively, Pine Script operates in a sandboxed environment. A Pine Script strategy() can only calculate equity, drawdowns, and targets based on the trades the script itself executes. It cannot read the floating equity of trades you place manually on your mobile phone via IC Markets.
To implement this logic in TradingView, you must use strategy.equity, enable calc_on_every_tick = true so the floors are monitored intrabar, and use a state variable (isHalted) to permanently disable the script once your 2 to 6-week series goal or failure threshold is reached.