Page 2 of 3

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:15 pm
by PTScalper
3. The New York Overlap (14:00 - 16:30)

The Trap: Recency Bias and Sizing Hubris

Market Structure: Peak daily liquidity as US markets open and European markets prepare to close. Heavy macroeconomic data releases (e.g., CPI, NFP) inject sudden, massive volatility.

The Psychology: Decisions made during this block are heavily contaminated by what happened in the morning session. If the morning was highly profitable, the "house money effect" sets in—leading to oversized positions, overconfidence, and ignored stop-losses. If the morning was red, the sudden spike in New York volatility acts as a siren song for martingale sizing (doubling down) to force the account back to breakeven in a single trade.

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:15 pm
by PTScalper
4. Friday Afternoon (16:30 onwards)

The Trap: The "Clean Slate" Desperation

Market Structure: Institutional position squaring. Major players flatten their books to avoid weekend headline risk, leading to erratic, technically disconnected price movements and thinning liquidity.

The Psychology: The emotional need to finish the week on a high note entirely overrides mathematical probability. Traders will force sub-optimal setups simply because they refuse to carry a weekly drawdown into the weekend. This is exactly where a manageable -1R week spirals into a catastrophic -5R week, as traders attempt to fight institutional profit-taking with retail size.

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:16 pm
by PTScalper
Implementing a robust time-of-day lockout requires a centralized "gatekeeper" function that evaluates broker server time before evaluating any entry conditions. Because algorithmic systems run unattended, the logic must account for broker timezone offsets and handle open positions when a lockout window begins.

Here are the optimal architectural patterns for enforcing these lockouts across your specific development environments.

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:16 pm
by PTScalper
1. cTrader / C# (cAlgo) Implementation

In cTrader, rely strictly on Server.Time to prevent misalignment if the local machine or VPS time drifts. You expose the hours as parameters for easy optimization.

Code: Select all

[Parameter("Morning Start Hour", Group = "Time Lock", DefaultValue = 8)]
public int MorningStart { get; set; }

[Parameter("Midday Lockout Start", Group = "Time Lock", DefaultValue = 11)]
public int MiddayStart { get; set; }

[Parameter("Afternoon Restart", Group = "Time Lock", DefaultValue = 14)]
public int AfternoonStart { get; set; }

[Parameter("Friday Hard Stop Hour", Group = "Time Lock", DefaultValue = 16)]
public int FridayStop { get; set; }

private bool IsTradingAllowed()
{
    var now = Server.Time;
    
    // Friday afternoon block (squaring off)
    if (now.DayOfWeek == DayOfWeek.Friday && now.Hour >= FridayStop)
        return false;

    // Midday chop block
    if (now.Hour >= MiddayStart && now.Hour < AfternoonStart)
        return false;

    // Standard overnight block
    if (now.Hour < MorningStart)
        return false;

    return true;
}

protected override void OnTick()
{
    if (!IsTradingAllowed()) 
    {
        ManageOpenPositionsDuringLockout(); // Optional: Trail stops or flatten
        return; 
    }
    
    // Execute core strategy logic here
}

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:17 pm
by PTScalper
2. MetaTrader 5 (MQL5) Implementation

MQL5 requires converting the time to a structure to parse the specific day and hour. Use TimeTradeServer() rather than TimeCurrent(), as TimeCurrent() only updates when a new tick arrives, which can lag during the dead midday chop.

Code: Select all

input int MorningStart = 8;
input int MiddayStart = 11;
input int AfternoonStart = 14;
input int FridayStop = 16;

bool IsTradingAllowed()
{
    MqlDateTime dt;
    TimeToStruct(TimeTradeServer(), dt);
    
    // Friday afternoon block
    if (dt.day_of_week == 5 && dt.hour >= FridayStop)
        return false;
        
    // Midday chop block
    if (dt.hour >= MiddayStart && dt.hour < AfternoonStart)
        return false;
        
    // Overnight block
    if (dt.hour < MorningStart)
        return false;
        
    return true;
}

void OnTick()
{
    if(!IsTradingAllowed()) return;
    
    // Strategy logic
}

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:17 pm
by PTScalper
3. TradingView (Pine Script v5/v6)

Pine Script handles time differently, relying on session strings. This is highly efficient for backtesting visual confirmation.

Code: Select all

//@version=5
strategy("Time Lockout Strategy", overlay=true)

// Define allowed sessions in exchange timezone
// 08:00 to 11:00 (All Days), 14:00 to 16:30 (Mon-Thu), 14:00 to 16:00 (Fri)
morningSession = time(timeframe.period, "0800-1100:12345")
afternoonSession_MonThu = time(timeframe.period, "1400-1630:1234")
afternoonSession_Fri = time(timeframe.period, "1400-1600:5")

// Gatekeeper variable
inTradeWindow = not na(morningSession) or not na(afternoonSession_MonThu) or not na(afternoonSession_Fri)

// Background color for visual debugging
bgcolor(inTradeWindow ? color.new(color.green, 90) : color.new(color.red, 90))

if (inTradeWindow and entry_condition)
    strategy.entry("Long", strategy.long)
    
// Optional: Force close at end of Friday session
if (dayofweek == dayofweek.friday and hour >= 16)
    strategy.close_all(comment="Friday Flatten")

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:17 pm
by PTScalper
Critical Architectural Considerations

Broker Time vs. Local Time: Forex brokers (like IC Markets) operate on server time, usually UTC+2 or UTC+3 (depending on US Daylight Saving Time). Hardcoding hour == 8 assumes London Open aligns with broker time 8 AM. If your broker's time offset shifts in March and November while European DST shifts on different dates, your algorithm will execute an hour early or late for 2–3 weeks. Always anchor logic to the broker's specific server time timezone and audit it during DST transitions.

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:18 pm
by PTScalper
The "Soft Close" vs. "Hard Close": When IsTradingAllowed() flips to false at 16:00 on a Friday, you must dictate what happens to existing positions.

Hard Close: Immediately send a market order to close all open positions. Prevents weekend gapping risk entirely, but guarantees spread execution in thinning liquidity.

Soft Close (Trailing): Prevent new entries, but allow existing trades to run against their predefined Take Profit or a tightened trailing stop. This requires wrapping your order execution block inside the gatekeeper, but leaving your order management block outside of it.

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:18 pm
by PTScalper
A Soft Close architecture requires decoupling your position management loop from your entry signal loop. When the time lockout triggers, the gatekeeper blocks the entry method, but the position management method shifts into an "Aggressive Trail" state.

This approach secures profits as liquidity thins out, while keeping the position alive just in case the market makes a final directional push in your favor.

Here is how to implement this pattern in both C# (cTrader) and MQL5, using a structure that dynamically adjusts the trailing stop distance based on the current time window.

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:19 pm
by PTScalper
1. cTrader / C# Implementation

In cAlgo, we separate the trailing logic into its own method called on every tick. If the lockout is active, we apply a much tighter pip distance to choke the trade out naturally.

Code: Select all

[Parameter("Standard Trail (Pips)", Group = "Trailing", DefaultValue = 10)]
public double StandardTrail { get; set; }

[Parameter("Aggressive Lockout Trail (Pips)", Group = "Trailing", DefaultValue = 3)]
public double AggressiveTrail { get; set; }

protected override void OnTick()
{
    bool isTradingAllowed = IsTradingAllowed(); // From previous gatekeeper logic

    // 1. Manage open positions regardless of lockout state
    ManageTrailingStops(isTradingAllowed);

    // 2. Block new entries if in a lockout
    if (!isTradingAllowed) return;

    // 3. Evaluate new entry signals
    EvaluateEntrySignals();
}

private void ManageTrailingStops(bool isTradingAllowed)
{
    // Determine which trail distance to use based on the time window
    double activeTrailPips = isTradingAllowed ? StandardTrail : AggressiveTrail;
    double activeTrailDistance = activeTrailPips * Symbol.PipSize;

    foreach (var position in Positions.FindAll(Label, SymbolName))
    {
        if (position.TradeType == TradeType.Buy)
        {
            double newStopLoss = Symbol.Bid - activeTrailDistance;
            
            // Only modify if the new SL is higher than the current SL (securing more profit)
            if (position.StopLoss == null || newStopLoss > position.StopLoss)
            {
                ModifyPosition(position, newStopLoss, position.TakeProfit);
            }
        }
        else if (position.TradeType == TradeType.Sell)
        {
            double newStopLoss = Symbol.Ask + activeTrailDistance;
            
            // Only modify if the new SL is lower than the current SL
            if (position.StopLoss == null || newStopLoss < position.StopLoss)
            {
                ModifyPosition(position, newStopLoss, position.TakeProfit);
            }
        }
    }
}