Page 3 of 3

Re: Heat Maps of Your Performance by Day and Hour

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

In MQL5, we use the CTrade library for execution. The architecture remains the same: the state of the time window dictates the strictness of the stop modification.

Code: Select all

#include <Trade\Trade.mqh>
CTrade trade;

input double StandardTrailPips = 10.0;
input double AggressiveTrailPips = 3.0;

void OnTick()
{
    bool allowed = IsTradingAllowed();
    
    // Always manage open positions
    ManageTrailingStops(allowed);
    
    // Gatekeeper for new entries
    if(!allowed) return;
    
    // Entry logic...
}

void ManageTrailingStops(bool isTradingAllowed)
{
    double activeTrail = isTradingAllowed ? StandardTrailPips : AggressiveTrailPips;
    double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
    double trailDistance = activeTrail * 10 * point; // Assuming 5-digit broker

    for(int i = PositionsTotal() - 1; i >= 0; i--)
    {
        ulong ticket = PositionGetTicket(i);
        if(PositionGetString(POSITION_SYMBOL) != _Symbol) continue;
        
        double currentStop = PositionGetDouble(POSITION_SL);
        double currentTakeProfit = PositionGetDouble(POSITION_TP);
        long type = PositionGetInteger(POSITION_TYPE);
        
        if(type == POSITION_TYPE_BUY)
        {
            double currentBid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
            double newStop = currentBid - trailDistance;
            
            if(currentStop == 0 || newStop > currentStop)
            {
                trade.PositionModify(ticket, newStop, currentTakeProfit);
            }
        }
        else if(type == POSITION_TYPE_SELL)
        {
            double currentAsk = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
            double newStop = currentAsk + trailDistance;
            
            if(currentStop == 0 || newStop < currentStop)
            {
                trade.PositionModify(ticket, newStop, currentTakeProfit);
            }
        }
    }
}

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:19 pm
by PTScalper
Critical Edge Cases for Scalpers

When tightening stops programmatically during low-liquidity periods, you must engineer around spread widening.

The Spread-Out Trap: On Raw ECN accounts, spreads during the midday chop might hover near 0.0 pips, but on Friday afternoons (or during the 23:59 server rollover), spreads can artificially widen by 2 to 5 pips as liquidity providers pull their quotes.

The Solution: If you set your AggressiveTrail to 2 pips, the widened spread alone will trigger your Stop Loss instantly, resulting in horrible slippage. Your aggressive trail distance must always be structurally larger than the maximum expected spread of that time block.

Re: Heat Maps of Your Performance by Day and Hour

Posted: Wed Oct 14, 2026 3:19 pm
by PTScalper
Instead of a fixed pip distance, an alternative approach for the Soft Close is a Fractal or Candle-Based Trail. Rather than trailing by 3 pips, you program the bot to trail the Stop Loss to the High/Low of the previous M5 or M15 candle once the lockout begins. This allows the trade to breathe technically while strictly preventing it from reversing the current micro-trend.