Advertisement IC Markets

FundingPips: weekend gap policy vs accidental holds

Discuss 1-minute to 15-minute price action setups, fading intraday momentum, key support/resistance zones, and proven short-term trading methodologies.
PTScalper
Site Admin
Posts: 7533
Joined: Mon Jul 20, 2026 1:28 pm

Re: FundingPips: weekend gap policy vs accidental holds

Post by PTScalper »

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.

cTrader Auto-Flatten cBot

Code: Select all

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class FridayAutoFlatten : Robot
    {
        [Parameter("Flatten Hour (Server Time)", DefaultValue = 22, MinValue = 0, MaxValue = 23)]
        public int FlattenHour { get; set; }

        [Parameter("Flatten Minute", DefaultValue = 50, MinValue = 0, MaxValue = 59)]
        public int FlattenMinute { get; set; }

        [Parameter("Cancel Pending Orders?", DefaultValue = true)]
        public bool CancelPending { get; set; }

        protected override void OnStart()
        {
            // 1-second timer guarantees execution independently of incoming market ticks
            Timer.Start(TimeSpan.FromSeconds(1));
        }

        protected override void OnTimer()
        {
            var now = Server.Time;

            // Trigger only on Friday at or after the target time
            if (now.DayOfWeek == DayOfWeek.Friday)
            {
                if (now.Hour > FlattenHour || (now.Hour == FlattenHour && now.Minute >= FlattenMinute))
                {
                    if (Positions.Count > 0 || (CancelPending && PendingOrders.Count > 0))
                    {
                        FlattenAll();
                    }
                }
            }
        }

        private void FlattenAll()
        {
            // Snapshot the collections to safely iterate while items are being removed
            var positionsToClose = Positions.ToArray();
            
            foreach (var position in positionsToClose)
            {
                // Asynchronous execution prevents thread blocking during bulk closures
                ClosePositionAsync(position, OnTradeResult);
            }

            if (CancelPending)
            {
                var ordersToCancel = PendingOrders.ToArray();
                
                foreach (var order in ordersToCancel)
                {
                    CancelPendingOrderAsync(order, OnTradeResult);
                }
            }
        }

        private void OnTradeResult(TradeResult result)
        {
            if (!result.IsSuccessful)
            {
                Print("Flatten execution failed for {0}. Error: {1}", 
                      result.Position?.Id ?? result.PendingOrder?.Id, 
                      result.Error);
            }
        }
    }
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Recommended broker for automated trading & scalping IC Markets
PTScalper
Site Admin
Posts: 7533
Joined: Mon Jul 20, 2026 1:28 pm

Re: FundingPips: weekend gap policy vs accidental holds

Post by PTScalper »

Implementation Details

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.
LondonScalper
Posts: 965
Joined: Sat Sep 05, 2026 7:54 am

Re: FundingPips: weekend gap policy vs accidental holds

Post by LondonScalper »

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?
LondonNewsTrader
Posts: 421
Joined: Mon Sep 21, 2026 9:30 am

Re: FundingPips: weekend gap policy vs accidental holds

Post by LondonNewsTrader »

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.
FXS Prop Desk
Posts: 1478
Joined: Wed Oct 07, 2026 9:52 am

Re: FundingPips: weekend gap policy vs accidental holds

Post by FXS Prop Desk »

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.
FXS Official Team | The Idea Lab & Strategy
Post Reply