Page 2 of 2

Re: Platform locks and checklists against revenge trading

Posted: Sun Oct 04, 2026 10:50 pm
by PTScalper
Integrating with your Execution Scripts

Because these monitors use GlobalVariableSet("AMYGDALA_LOCK", lockReleaseTime), the state persists at the terminal level—even if you close and reopen MetaTrader.

If you use custom cAlgo/MQL scripts to execute your market orders instantly, simply add this one-liner to the very top of their execution logic:

Code: Select all

if(GlobalVariableCheck("AMYGDALA_LOCK") && TimeCurrent() < GlobalVariableGet("AMYGDALA_LOCK")) 
    return; // Silently drop the order request

Re: Platform locks and checklists against revenge trading

Posted: Sun Oct 04, 2026 10:50 pm
by PTScalper
This creates a two-pronged defense. Even if you somehow manage to manually open a new chart and press F9 to load the order window before the timer sweeps and closes it, your automated entry scripts will completely ignore your hotkeys until the cooldown expires.

Re: Platform locks and checklists against revenge trading

Posted: Sun Oct 04, 2026 10:51 pm
by PTScalper
In cTrader, we write the solution in C# using the cAlgo API. Since you are deeply familiar with the .NET ecosystem, you will appreciate how cTrader handles this compared to MetaTrader.

cTrader’s sandbox does not natively allow us to loop through OS-level window handles to force-close other charts without relying on messy Win32 interop. However, it gives us something arguably better: Account-level Event Interception and WPF-style UI rendering.

We can build a cBot that runs on a single chart and acts as an account-level warden. It does three things:

State Persistence: It saves the lockout timestamp to cTrader's LocalStorage. If you restart the terminal, it reads the file and enforces the remainder of the lock.

UI Overlay: When locked, it renders a massive, semi-transparent red WPF Border over the chart that absorbs all mouse clicks (IsHitTestVisible = true), effectively blinding the workspace.

The Punisher (Auto-Close): It subscribes to the Positions.Opened event. If you manage to bypass the visual lock (e.g., by placing a trade from your phone or another chart), the cBot detects the new position and instantly closes it at market within milliseconds.

Re: Platform locks and checklists against revenge trading

Posted: Sun Oct 04, 2026 10:51 pm
by PTScalper
Here is the C# cBot implementation:

Code: Select all

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.UI;

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

        [Parameter("Rolling Window for 2 Losses (Min)", DefaultValue = 30)]
        public int LossWindowMinutes { get; set; }

        [Parameter("Cooldown Lock Period (Min)", DefaultValue = 20)]
        public int CooldownMinutes { get; set; }

        private DateTime _lockReleaseTime;
        private Border _lockoutUI;
        private TextBlock _lockoutText;

        protected override void OnStart()
        {
            // 1. Check LocalStorage for persistence across terminal restarts
            if (LocalStorage.HasObject("AmygdalaLockRelease"))
            {
                _lockReleaseTime = LocalStorage.GetObject<DateTime>("AmygdalaLockRelease");
            }

            // 2. Build the UI Overlay (WPF-style)
            BuildUI();

            // 3. Subscribe to Account Events
            History.HistoryItemAdded += OnHistoryAdded;
            Positions.Opened += OnPositionOpened;

            // 4. Start the checking loop
            Timer.Start(1); 
            EvaluateLockStatus();
        }

        protected override void OnTimer()
        {
            EvaluateLockStatus();
        }

        private void OnHistoryAdded(HistoryItemEventArgs args)
        {
            // Only care about closed positions, not deposits/withdrawals
            if (args.HistoryItem.TradeType != TradeType.Buy && args.HistoryItem.TradeType != TradeType.Sell)
                return;

            EvaluateLockConditions();
        }

        // ==============================================================================
        // THE PUNISHER: Intercept and close revenge trades instantly
        // ==============================================================================
        private void OnPositionOpened(PositionOpenedEventArgs args)
        {
            if (Server.Time < _lockReleaseTime)
            {
                Print("AMYGDALA LOCK ACTIVE: Intercepting and closing manual order.");
                ClosePositionAsync(args.Position);
            }
        }

        // ==============================================================================
        // CORE LOGIC: History Evaluation
        // ==============================================================================
        private void EvaluateLockConditions()
        {
            // If already locked, don't re-evaluate until it expires
            if (Server.Time < _lockReleaseTime) return;

            // Get today's trades using LINQ
            var todayTrades = History.Where(h => h.ClosingTime.Date == Server.Time.Date).ToList();
            
            // 1. Check Daily Limit
            double dailyPnL = todayTrades.Sum(h => h.NetProfit);
            if (dailyPnL <= -DailyLossLimit)
            {
                TriggerLock(Server.Time.Date.AddDays(1), "DAILY LOSS LIMIT HIT");
                return;
            }

            // 2. Check 30-Minute / 2-Loss Rule
            var recentLosses = todayTrades
                .Where(h => h.NetProfit < 0)
                .OrderByDescending(h => h.ClosingTime)
                .Take(2)
                .ToList();

            if (recentLosses.Count == 2)
            {
                TimeSpan timeBetweenLosses = recentLosses[0].ClosingTime - recentLosses[1].ClosingTime;
                
                if (timeBetweenLosses.TotalMinutes <= LossWindowMinutes)
                {
                    TriggerLock(Server.Time.AddMinutes(CooldownMinutes), "AMYGDALA LOCK ACTIVE\nCheck your paper checklist.");
                }
            }
        }

        private void TriggerLock(DateTime releaseTime, string message)
        {
            _lockReleaseTime = releaseTime;
            LocalStorage.SetObject("AmygdalaLockRelease", _lockReleaseTime);
            
            Chart.DrawStaticText("lock_msg", "SYSTEM LOCKED", VerticalAlignment.Top, HorizontalAlignment.Left, Color.Red);
            Print(message);
        }

        private void EvaluateLockStatus()
        {
            bool isLocked = Server.Time < _lockReleaseTime;
            
            if (isLocked)
            {
                if (!Chart.Controls.Contains(_lockoutUI))
                {
                    Chart.AddControl(_lockoutUI);
                }
                
                TimeSpan remaining = _lockReleaseTime - Server.Time;
                _lockoutText.Text = $"SYSTEM LOCKED\nUnlocks in: {remaining:hh\\:mm\\:ss}\n\nDo not bypass. Check your playbook.";
            }
            else
            {
                if (Chart.Controls.Contains(_lockoutUI))
                {
                    Chart.RemoveControl(_lockoutUI);
                    LocalStorage.RemoveObject("AmygdalaLockRelease"); // Clean up
                }
            }
        }

        private void BuildUI()
        {
            _lockoutText = new TextBlock
            {
                Text = "",
                ForegroundColor = Color.White,
                FontSize = 24,
                FontWeight = FontWeight.ExtraBold,
                TextAlignment = TextAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            _lockoutUI = new Border
            {
                BackgroundColor = Color.FromArgb(220, 180, 0, 0), // Opaque Red
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                IsHitTestVisible = true, // This blocks mouse clicks from passing through to the chart
                Child = _lockoutText
            };
        }
    }
}

Re: Platform locks and checklists against revenge trading

Posted: Sun Oct 04, 2026 10:51 pm
by PTScalper
Why this architecture fits your workflow:

Because you are running custom algorithmic tools and likely have a multi-chart workspace setup, cTrader's Positions.Opened event is the ultimate safety net.

If your amygdala gets hijacked and you bypass the WPF overlay by opening a fresh workspace, a new chart, or even grabbing your mobile phone to execute a market order, the server-side logic of cTrader instantly reports the new position to this cBot. The cBot fires ClosePositionAsync(args.Position) and neutralizes the trade before you have time to blink.

The only way to override it is to literally stop the cBot instance—which forces you to deliberately navigate to the Automate tab, click stop, and bypass your own safeguards, creating the exact friction your paper checklist requires.

Re: Platform locks and checklists against revenge trading

Posted: Mon Oct 05, 2026 7:57 am
by LondonScalper
I agree the lock is a tourniquet. I do not agree that deeper market understanding makes it obsolete.

Twenty years of reading tape did not stop the ten-minute spiral after two losers. What stopped it was the forced restart and the log line. On mornings when I actually understand the session well, the script rarely fires — that part of your point I buy. On mornings when I am wrong and annoyed, understanding is the first thing that leaves the room.

So I keep both layers. The checklist for the ordinary pause after a single loss. The lock for the days when I would otherwise talk myself into a third ticket. If the desire ever truly vanishes, the script can sit unused. I will not delete it on the strength of a good month.

Re: Platform locks and checklists against revenge trading

Posted: Sat Oct 17, 2026 9:12 am
by FXS Prop Desk
Understanding mechanics does reduce the emotional sting of losses. That said, many experienced traders still keep a lock as a backup, because fatigue or outside stress can affect anyone regardless of knowledge. A lock that is rarely triggered costs nothing, while it can prevent the one bad day that matters.

The lock can also be set to a looser threshold than the usual daily limit, so it only triggers on truly bad days, while understanding handles the rest.