In cTrader, automated scripts (cBots) are written in C# using the .NET framework. Because the cAlgo API is heavily event-driven, we can use the OnTimer method to execute a 1-second heartbeat loop, ensuring the flatten command triggers precisely on time regardless of market liquidity or tick volume.
Unlike MQL4/5, modifying a collection while iterating over it in C# throws an InvalidOperationException. To prevent this, the logic takes a snapshot of the Positions and PendingOrders collections using .ToArray() before initiating the closures.
Account-Wide Execution: By calling the global Positions collection rather than Positions.FindAll(SymbolName), this cBot acts as a master kill-switch for the entire account. You only need to run it on a single chart instance.
Asynchronous Trade API: Utilizing ClosePositionAsync and CancelPendingOrderAsync instead of synchronous methods ensures that the cBot doesn't hang waiting for the server to acknowledge each individual closure. This is highly effective if you have multiple micro-lots or grid positions open.
Server Time Coordination: Server.Time automatically syncs with your broker's timezone (usually GMT+2 or GMT+3), ensuring the FlattenHour aligns perfectly with the exchange close, regardless of the local time zone on your VPS or workstation.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper wrote:For FundingPips 1-Step & Standard 2-Step Master Accounts the system force-closes open positions at Friday market close — automated liquidation, not a hard breach. Zero Master Accounts: weekend hold is a hard baseline rule; a leftover micro lot triggers immediate termination.
That split is exactly the operational detail the marketing page never stresses. Sunday open with blown spreads is already expensive; discovering your model treats the same leftover micro lot as either a forced flat or an unappealable breach is how funded accounts die on process, not on edge. I take your broader scepticism on challenge layers as noted — artificial rules are another counterparty — but while people still sit those accounts, the Friday flatten checklist has to match the exact model name, not the brand.
Desk rule on any funded book I touch: Friday 60 minutes before cash close = flatten script + visual book check + model-tag confirmation (Zero vs Master). No "I will close after this candle." Accidental hold is a platform and habit failure, not bad luck.
For firms that only auto-liquidate rather than breach, have you seen Sunday reopen slippage still count against daily loss, or is the force-close treated as a clean slate into the new week?
PTScalper wrote: Because the cAlgo API is heavily event-driven, we can use the OnTimer method to execute a 1-second heartbeat loop, ensuring the flatten command triggers precisely on time regardless of market liquidity or tick volume.
Check the default time before relying on this. The robot is declared with TimeZone = TimeZones.UTC, so Server.Time is UTC, and 22:50 on Friday in UTC is after the weekly close all year. The FX market closes at 5 p.m. New York, which is 21:00 UTC in summer and 22:00 UTC in winter. With the defaults, the flatten would fire after the market has already closed, so positions would be carried into the weekend anyway. Something like 20:30 UTC in summer and 21:30 in winter, or a time defined in New York terms, would be safer.
The timer also calls FlattenAll every second while positions remain. Because the closes are asynchronous, the same position can receive several close requests before the first one completes, which produces a stream of errors in the log. A flag set when the flatten starts and cleared once everything is gone would stop that.
Snapshotting the collections with ToArray() is correct and a common source of bugs when people skip it.
Clear explanation of how the risk engine treats a gap. One related point for anyone holding over the weekend on a funded account: the stop loss offers no protection at the gap level, it simply becomes a market order at the first available price. So the realistic worst case for a weekend hold is the size of the largest historical gap on that pair, not the stop distance. For gold, looking at the biggest Sunday gaps of the last couple of years and sizing so that a gap of that size stays inside the daily limit is a simple sanity check.