In MT5, the structure is more modern. We use HistorySelect() to fetch the account's historical "Deals" rather than looping through a generic order pool, and we utilize the built-in CTrade library to easily kill open positions.
Placing these gates at the absolute top of the OnTick() event handler means that regardless of what crazy signals your indicators are throwing, the EA physically cannot fire a trade if you are violating your pre-written, calm-minded risk rules.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
For cTrader, you must write your logic using cTrader Automate (formerly cAlgo) in C#.
Unlike MT4/MT5, cTrader is built on modern C# (.NET), which makes working with historical trades and account states much cleaner. We can use standard LINQ queries to quickly calculate daily profit or filter out recent consecutive losses.
Here is the complete cBot skeleton that hard-codes your three risk rules directly into the OnTick() loop.
1.) Clean History Tracking (IsDailyLossReached): Instead of parsing arrays by ID loops, cTrader allows us to use LINQ .Where(t => t.ClosingTime.Date == Server.Time.Date) to instantly pull today's closed trades and .Sum() their NetProfit. We add this to Account.Equity - Account.Balance to see exactly where we stand intraday.
2.) Safe Volume Halving (NormalizeVolumeInUnits): cTrader is extremely strict about order sizes matching the broker's minimum step volume. If your Base Volume is 150,000 units, dividing it by 2 is 75,000. If the broker only allows increments of 10,000, the order will bounce. Symbol.NormalizeVolumeInUnits(currentVolume, RoundingMode.Down) protects your script from crashing when halving your size.
3.) Asynchronous Flattening (FlattenAccount): When dealing with extreme market events (like the News Blackout window), you don't want the bot waiting for one position to close before sending the command for the next. Using ClosePositionAsync() rapidly fires the close commands for all open trades and pending limit/stop orders simultaneously.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper wrote: We use HistorySelect() to fetch the account's historical "Deals" rather than looping through a generic order pool, and we utilize the built-in CTrade library to easily kill open positions.
One subtle issue in IsDailyLossReached(). The floating part is equity minus balance, which includes the full open P&L of positions opened before midnight. A trade carried overnight with a 300 loss counts the whole 300 against today's limit the moment the new day starts, even if it hasn't moved since. Depending on the intention that may be fine, but it can trigger the shutdown at the first tick of the day.
The news blackout uses one fixed window, 13:45 to 14:15 in server time. On most GMT+2 or GMT+3 MT5 servers the 8:30 New York releases land at 15:30, and central bank decisions are at different times again, so a single hard-coded window will miss most of the events it is meant to cover. Reading the times from a small calendar file each morning is more work but much safer.
Closing everything at the start of the window is the right instinct. Fifteen minutes before a release is far cheaper than the minute after it.
The intraday loss function is a good backstop, and one detail matters a lot with it: the limit counts in the script's currency and only for trades the strategy itself made. Manual trades placed on the same account do not count. For anyone using it as a personal stop, it should be treated as a reminder system, not account-level protection. The broker-side or platform-side daily loss setting, if available, is the one that actually stops trading, since it sees every position on the account.