Advertisement IC Markets

Desk deep dive: when adding an EA

Discuss 1-minute to 15-minute price action setups, fading intraday momentum, key support/resistance zones, and proven short-term trading methodologies.
LondonNewsTrader
Posts: 421
Joined: Mon Sep 21, 2026 9:30 am

Desk deep dive: when adding an EA

Post by LondonNewsTrader »

Adding an EA to a discretionary news desk is usually a mistake I make when I am tired of clicking.

The only EA I will consider has one job: flatten or block. Not entry. A script that refuses orders inside a blackout window, or that closes everything if daily loss limit is hit, earns its place. A script that "finds" London breakouts while I sleep does not - not on my book.

Checklist before any EA goes on the live VPS:

- What exact order actions can it take?
- Does it read the same symbol names as my charts?
- What does it do on connection loss?
- Can I kill it in one click without killing the terminal?
- Is it off by default on Sunday and only enabled after I check the calendar?

I run any new helper on demo through one full CPI week before live. If I cannot explain its behaviour in two sentences on the news sheet, it stays off. The desk deep dive is really a boundary: automation for defence, discretion for offence.
Recommended broker for automated trading & scalping IC Markets
PTScalper
Site Admin
Posts: 7923
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk deep dive: when adding an EA

Post by PTScalper »

LondonNewsTrader wrote: Mon Oct 05, 2026 7:43 pm Adding an EA to a discretionary news desk is usually a mistake I make when I am tired of clicking.

The only EA I will consider has one job: flatten or block. Not entry. A script that refuses orders inside a blackout window, or that closes everything if daily loss limit is hit, earns its place. A script that "finds" London breakouts while I sleep does not - not on my book.

Checklist before any EA goes on the live VPS:

- What exact order actions can it take?
- Does it read the same symbol names as my charts?
- What does it do on connection loss?
- Can I kill it in one click without killing the terminal?
- Is it off by default on Sunday and only enabled after I check the calendar?

I run any new helper on demo through one full CPI week before live. If I cannot explain its behaviour in two sentences on the news sheet, it stays off. The desk deep dive is really a boundary: automation for defence, discretion for offence.
Hi LondonNewsTrader,

We’ve all been there. You’ve been staring at 15-minute price action all week, grinding through the chop, waiting for the right setup to form. Fatigue sets in. That’s exactly when the temptation hits: Adding an EA to a discretionary news desk is usually a mistake I make when I am tired of clicking.

When you are mentally drained, the idea of a script taking the wheel feels like a massive relief. But over the years—and after writing more than my fair share of custom scripts in MQL and cAlgo—I’ve established a hard line on what is allowed to run alongside my manual trading.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7923
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk deep dive: when adding an EA

Post by PTScalper »

My core rule is simple: Automation for defense, discretion for offense.

The only EA I will ever consider running has one job: flatten the book or block the terminal. Absolutely no entries. A script that refuses orders inside a news blackout window, or a hard-coded equity monitor that closes everything the second a daily loss limit is hit—that script earns its CPU cycles.

A script that supposedly "finds" London breakouts while I sleep does not. Not on my book. As a discretionary trader, your edge relies on reading raw candlestick structure and understanding the higher timeframe context. An EA doesn’t see that a move is just a liquidity sweep on the daily chart; it just blindly executes a breakout condition.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7923
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk deep dive: when adding an EA

Post by PTScalper »

Before any compiled EA goes anywhere near my live VPS, it must pass a strict checklist:

What exact order actions can it take? It should only have the permission and logic to execute close commands or reject inputs. If there is a function anywhere in the code for opening a new position, it’s a liability.

Does it read the same symbol names as my charts? The classic broker trap. Does it handle suffixes correctly? If I'm trading spot gold, does it know XAUUSD.pro is the same as XAUUSD, or will it fail to reconcile my open positions when it needs to close them?

What does it do on connection loss? If the VPS drops the connection to the broker server, does the script panic? Does it retry infinitely and flood the logs, or does it have a graceful reconnect protocol?

Can I kill it in one click without killing the terminal? When the market gets entirely unhinged, I don't have time to dig through properties menus. There needs to be a UI button right on the chart to instantly detach the EA without shutting down the whole terminal and blinding myself to the charts.

Is it off by default on Sunday and only enabled after I check the calendar? The EA must initialize in a disabled state on startup. It stays dormant until I physically review the week's economic calendar and explicitly toggle it on.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7923
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk deep dive: when adding an EA

Post by PTScalper »

Finally, there is the stress test. I run any new helper script on a demo account through one full CPI week before it ever touches live funds. A CPI release brings widened spreads, brutal slippage, and massive tick volume. If the script's execution logic can't handle that chaotic environment without freezing, it’s useless.

If I cannot explain the script's exact behavior in two sentences on my news prep sheet, it stays off. This deep dive really establishes a firm boundary for the desk: let the code protect the capital, and let your brain find the setups.

Curious to hear how the rest of you handle automation alongside your manual execution. Has anyone found an entry EA that actually complements a purely discretionary workflow, or are you all in the "defense only" camp with me?
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7923
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk deep dive: when adding an EA

Post by PTScalper »

To keep strictly to the "automation for defense, discretion for offense" boundary, this C# cBot for cTrader does exactly one thing: monitors your equity and flattens the book if your daily loss limit is breached.

It hits every requirement from the desk checklist: it contains zero entry logic, initializes offline by default (requiring you to actively enable it), and features a one-click UI kill switch right on the chart so you don't have to fight with the terminal menus during a fast market.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7923
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk deep dive: when adding an EA

Post by PTScalper »

Ctrader EA version 1.0

Code: Select all

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DailyLossDefender : Robot
    {
        [Parameter("Max Daily Loss ($)", DefaultValue = 500, MinValue = 0)]
        public double MaxDailyLoss { get; set; }

        [Parameter("Start Enabled (Default OFF)", DefaultValue = false)]
        public bool StartEnabled { get; set; }

        private bool _isActive;
        private Button _toggleButton;

        protected override void OnStart()
        {
            // Initializes in a disabled state by default
            _isActive = StartEnabled;
            
            // Create the One-Click UI Kill Switch on the chart
            _toggleButton = new Button
            {
                Text = _isActive ? "DEFENDER: ACTIVE" : "DEFENDER: OFF",
                BackgroundColor = _isActive ? Color.DarkGreen : Color.DarkRed,
                ForegroundColor = Color.White,
                VerticalAlignment = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Right,
                Margin = new Thickness(10),
                Width = 150,
                Height = 35
            };
            
            _toggleButton.Click += OnToggleButtonClick;
            Chart.AddControl(_toggleButton);
            
            Print("Defender initialized. State: {0}", _isActive ? "Active" : "Off");
        }

        private void OnToggleButtonClick(ButtonClickEventArgs args)
        {
            _isActive = !_isActive;
            UpdateButtonUI();
            Print("Defender manually set to: {0}", _isActive ? "Active" : "Off");
        }

        private void UpdateButtonUI()
        {
            _toggleButton.Text = _isActive ? "DEFENDER: ACTIVE" : "DEFENDER: OFF";
            _toggleButton.BackgroundColor = _isActive ? Color.DarkGreen : Color.DarkRed;
        }

        protected override void OnTick()
        {
            // If the script is turned off, ignore all ticks
            if (!_isActive) return;

            // Calculate today's realized PnL based on the server date
            var todaysHistory = History.Where(t => t.ClosingTime.Date == Server.Time.Date);
            double realizedPnL = todaysHistory.Sum(t => t.NetProfit);

            // Calculate current floating unrealized PnL
            double unrealizedPnL = Positions.Sum(p => p.NetProfit);

            double totalDailyPnL = realizedPnL + unrealizedPnL;

            // Check if the daily drawdown threshold is breached
            if (totalDailyPnL <= -MaxDailyLoss)
            {
                ExecuteFlatten();
            }
        }

        private void ExecuteFlatten()
        {
            Print("MAX DAILY LOSS REACHED! Flattening the book...");

            // Close all open positions at market
            foreach (var position in Positions)
            {
                ClosePositionAsync(position);
            }

            // Cancel any pending limit/stop orders
            foreach (var order in PendingOrders)
            {
                CancelPendingOrderAsync(order);
            }

            // Immediately deactivate the bot to prevent loops
            _isActive = false;
            UpdateButtonUI();
            
            Print("Book flattened. Defender deactivated. Walk away for the day.");
        }
    }
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7923
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk deep dive: when adding an EA

Post by PTScalper »

Why this structure works for a discretionary desk:

Asynchronous Execution: It uses ClosePositionAsync and CancelPendingOrderAsync to fire off the flatten commands concurrently, rather than waiting for the broker server to confirm each ticket sequentially.

Account-Wide Coverage: Instead of locking onto a specific symbol string (which avoids the XAUUSD vs XAUUSD.pro suffix trap), it iterates through the entire Positions collection. If it's open, it dies.

No Entry Code: There is physically no code in this class capable of opening a position, eliminating any risk of a rogue loop firing off market orders.

You can easily extend the OnTick logic to read the system clock and block out specific time windows (like CPI or NFP) by forcing _isActive = false if Server.Time falls within those restricted minutes.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7923
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk deep dive: when adding an EA

Post by PTScalper »

This extension brings the bot fully in line with the original forum post checklist. We are adding the News Blackout Window (which actively refuses manual entries by instantly closing them if you get "click-happy" during a CPI spike) and a Friday Auto-Flatten to kill weekend gap risk.

It also upgrades the UI to give you a real-time HUD of your daily PnL and active defensive states, so you don't have to look away from your price action analysis to know where your equity stands.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7923
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk deep dive: when adding an EA

Post by PTScalper »

Ctrader version 2.0

Code: Select all

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class UltimateDeskDefender : Robot
    {
        #region Parameters

        [Parameter("Start Enabled (Default OFF)", Group = "Initialization", DefaultValue = false)]
        public bool StartEnabled { get; set; }

        [Parameter("Max Daily Loss ($)", Group = "Risk Limits", DefaultValue = 500, MinValue = 0)]
        public double MaxDailyLoss { get; set; }

        [Parameter("Enable News Blackout", Group = "News Defense", DefaultValue = true)]
        public bool EnableNewsBlackout { get; set; }

        [Parameter("Blackout Start (HH:mm)", Group = "News Defense", DefaultValue = "13:25")]
        public string BlackoutStartStr { get; set; }

        [Parameter("Blackout End (HH:mm)", Group = "News Defense", DefaultValue = "13:35")]
        public string BlackoutEndStr { get; set; }

        [Parameter("Friday Flat Enable", Group = "Weekend Defense", DefaultValue = true)]
        public bool EnableFridayClose { get; set; }

        [Parameter("Friday Close Time (HH:mm)", Group = "Weekend Defense", DefaultValue = "20:45")]
        public string FridayCloseTimeStr { get; set; }

        #endregion

        private bool _isActive;
        private Button _toggleButton;
        private TextBlock _statusText;
        
        private TimeSpan _blackoutStart;
        private TimeSpan _blackoutEnd;
        private TimeSpan _fridayCloseTime;

        protected override void OnStart()
        {
            // Parse time configurations
            TimeSpan.TryParse(BlackoutStartStr, out _blackoutStart);
            TimeSpan.TryParse(BlackoutEndStr, out _blackoutEnd);
            TimeSpan.TryParse(FridayCloseTimeStr, out _fridayCloseTime);

            _isActive = StartEnabled;

            // Hook into the position opened event to monitor manual clicks
            Positions.Opened += OnPositionOpened;

            BuildUI();
            Print("Ultimate Defender initialized. State: {0}", _isActive ? "Active" : "Off");
        }

        private void BuildUI()
        {
            var panel = new StackPanel
            {
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(10),
                BackgroundColor = Color.FromArgb(180, 20, 20, 20)
            };

            _toggleButton = new Button
            {
                Text = _isActive ? "DEFENDER: ON" : "DEFENDER: OFF",
                BackgroundColor = _isActive ? Color.DarkGreen : Color.DarkRed,
                ForegroundColor = Color.White,
                Width = 160,
                Height = 35,
                Margin = new Thickness(5)
            };
            _toggleButton.Click += OnToggleButtonClick;

            _statusText = new TextBlock
            {
                Text = "Daily PnL: $0.00\nStatus: Monitoring",
                ForegroundColor = Color.LightGray,
                Margin = new Thickness(5),
                TextAlignment = TextAlignment.Center
            };

            panel.AddChild(_toggleButton);
            panel.AddChild(_statusText);
            Chart.AddControl(panel);
        }

        private void OnToggleButtonClick(ButtonClickEventArgs args)
        {
            _isActive = !_isActive;
            UpdateButtonUI();
        }

        private void UpdateButtonUI()
        {
            _toggleButton.Text = _isActive ? "DEFENDER: ON" : "DEFENDER: OFF";
            _toggleButton.BackgroundColor = _isActive ? Color.DarkGreen : Color.DarkRed;
            if (!_isActive) _statusText.Text = "System Offline";
        }

        protected override void OnTick()
        {
            if (!_isActive) return;

            double totalDailyPnL = CalculateDailyPnL();
            UpdateStatusText(totalDailyPnL);

            // 1. Daily Drawdown Defense
            if (totalDailyPnL <= -MaxDailyLoss)
            {
                Print("DEFENSE: Max Daily Loss Hit.");
                ExecuteFlatten("Daily Limit Breached");
                return;
            }

            // 2. Weekend Gap Defense (Friday Auto-Close)
            if (EnableFridayClose && Server.Time.DayOfWeek == DayOfWeek.Friday && Server.Time.TimeOfDay >= _fridayCloseTime)
            {
                if (Positions.Count > 0 || PendingOrders.Count > 0)
                {
                    Print("DEFENSE: Friday Close Time Hit.");
                    ExecuteFlatten("Weekend Gap Defense");
                }
            }
        }

        // 3. News Blackout Defense (Refuses manual orders)
        private void OnPositionOpened(PositionOpenedEventArgs args)
        {
            if (!_isActive || !EnableNewsBlackout) return;

            var currentTime = Server.Time.TimeOfDay;
            bool inBlackout = currentTime >= _blackoutStart && currentTime <= _blackoutEnd;

            if (inBlackout)
            {
                Print("DEFENSE: Manual order rejected inside News Blackout Window!");
                ClosePositionAsync(args.Position);
            }
        }

        private double CalculateDailyPnL()
        {
            var todaysHistory = History.Where(t => t.ClosingTime.Date == Server.Time.Date);
            double realizedPnL = todaysHistory.Sum(t => t.NetProfit);
            double unrealizedPnL = Positions.Sum(p => p.NetProfit);
            
            return realizedPnL + unrealizedPnL;
        }

        private void UpdateStatusText(double currentPnL)
        {
            var currentTime = Server.Time.TimeOfDay;
            bool inBlackout = EnableNewsBlackout && currentTime >= _blackoutStart && currentTime <= _blackoutEnd;

            string state = inBlackout ? "[NEWS BLACKOUT ACTIVE]" : "Monitoring";
            _statusText.Text = $"Daily PnL: ${Math.Round(currentPnL, 2)}\nStatus: {state}";
            _statusText.ForegroundColor = currentPnL < 0 ? Color.Salmon : Color.LightGreen;
        }

        private void ExecuteFlatten(string reason)
        {
            Print($"Executing Flatten. Reason: {reason}");

            foreach (var position in Positions) ClosePositionAsync(position);
            foreach (var order in PendingOrders) CancelPendingOrderAsync(order);

            _isActive = false;
            UpdateButtonUI();
            _statusText.Text = $"FLATTENED: {reason}";
            _statusText.ForegroundColor = Color.Red;
        }
    }
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Post Reply