Page 2 of 2

Re: EURUSD journal: how cost tags changed my behavior

Posted: Fri Oct 02, 2026 9:50 am
by PTScalper
Automation Integration

If you later transition this visualization into an executing cBot, separating the execution cost logic allows you to elegantly inject it into your order routing.

Instead of modifying your core strategy class, you can create a structural guardrail inside your execution wrapper:

Code: Select all

if (CostTag == "EXPENSIVE") 
{
    PlaceLimitOrder(TradeType.Buy, SymbolName, Volume, TargetPrice, "LondonOpenSweep");
} 
else 
{
    ExecuteMarketOrder(TradeType.Buy, SymbolName, Volume, "MidMorningSweep");
}

Re: EURUSD journal: how cost tags changed my behavior

Posted: Fri Oct 02, 2026 9:51 am
by PTScalper
To elevate this from a basic visual aid to a production-grade institutional tool, we need to strip out the loose strings and primitive data types and replace them with a robust architectural pattern.

Here is what makes the following cTrader C# implementation "Pro":

WPF-Style Control Panel: Instead of painting raw text onto the chart background, this builds a dedicated, stylized UI panel (HUD) using cTrader’s built-in UI controls (Border, StackPanel, TextBlock). It anchors cleanly, handles opacity, and avoids overlapping with price action.

Enum-Driven State Machine: Moving away from fragile boolean checks (limitOnly = true), we use strongly typed CostBucket and SetupType enums. This guarantees strict state management and makes the logic instantly portable to an executing cBot.

Separation of Concerns: The PA detection, microstructure cost evaluation, and UI rendering are decoupled into isolated, private methods.

Memory Management: Professional indicators explicitly destroy custom UI elements and chart objects in the OnDestroy() override to prevent memory leaks when changing timeframes or removing the tool.

Re: EURUSD journal: how cost tags changed my behavior

Posted: Fri Oct 02, 2026 9:51 am
by PTScalper
Production-Grade cTrader Implementation

Code: Select all

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ExecutionCostJournalPro : Indicator
    {
        // =========================================================================
        // PARAMETERS
        // =========================================================================
        [Parameter("Cheap Spread Ceiling (Pips)", DefaultValue = 0.4, Group = "Microstructure")]
        public double CheapSpreadPips { get; set; }

        [Parameter("Expensive Spread Floor (Pips)", DefaultValue = 1.1, Group = "Microstructure")]
        public double ExpensiveSpreadPips { get; set; }

        [Parameter("London Open Hour (UTC)", DefaultValue = 8, Group = "Time Windows")]
        public int LonOpenHour { get; set; }

        [Parameter("NY Open Hour (UTC)", DefaultValue = 13, Group = "Time Windows")]
        public int NyOpenHour { get; set; }

        [Parameter("Open Friction Duration (Mins)", DefaultValue = 15, Group = "Time Windows")]
        public int OpenDurationMins { get; set; }

        // =========================================================================
        // ENUMS & STATE
        // =========================================================================
        public enum CostBucket { Cheap, Normal, Expensive }
        public enum SetupType { None, BullishSweep, BearishSweep }

        // UI Elements
        private Border _hudContainer;
        private TextBlock _spreadText;
        private TextBlock _costBucketText;
        private TextBlock _executionText;

        // =========================================================================
        // INITIALIZATION
        // =========================================================================
        protected override void Initialize()
        {
            BuildControlPanel();
        }

        // =========================================================================
        // CORE CALCULATION LOOP
        // =========================================================================
        public override void Calculate(int index)
        {
            if (index < 2) return;

            // 1. Evaluate Current Hard-Right-Edge (Live Tick Data)
            if (IsLastBar)
            {
                double liveSpread = Math.Round(Symbol.Spread / Symbol.PipSize, 1);
                CostBucket liveCost = EvaluateCostState(Server.Time, liveSpread);
                UpdateControlPanel(liveSpread, liveCost);
            }

            // 2. Evaluate Historical Setup Conditions
            SetupType currentSetup = DetectPriceAction(index);
            
            if (currentSetup != SetupType.None)
            {
                // Proxy historical spread as 0 to force Time-Window evaluation
                CostBucket historicalCost = EvaluateCostState(Bars.OpenTimes[index], 0);
                DrawSetupTag(index, currentSetup, historicalCost);
            }
        }

        // =========================================================================
        // MICROSTRUCTURE LOGIC
        // =========================================================================
        private CostBucket EvaluateCostState(DateTime time, double spreadPips)
        {
            // Time-based execution friction takes precedence
            bool isHighFrictionWindow = (time.Hour == LonOpenHour || time.Hour == NyOpenHour) 
                                        && time.Minute < OpenDurationMins;

            if (isHighFrictionWindow || (spreadPips >= ExpensiveSpreadPips && spreadPips > 0))
                return CostBucket.Expensive;
            
            if (spreadPips > 0 && spreadPips <= CheapSpreadPips)
                return CostBucket.Cheap;

            return CostBucket.Normal;
        }

        // =========================================================================
        // STRATEGY LOGIC (ISOLATED)
        // =========================================================================
        private SetupType DetectPriceAction(int index)
        {
            // Replace with your actual edge (Engulfing used as placeholder)
            bool isBullish = Bars.ClosePrices[index] > Bars.OpenPrices[index] &&
                             Bars.ClosePrices[index - 1] < Bars.OpenPrices[index - 1] &&
                             Bars.ClosePrices[index] > Bars.OpenPrices[index - 1] &&
                             Bars.OpenPrices[index] < Bars.ClosePrices[index - 1];

            bool isBearish = Bars.ClosePrices[index] < Bars.OpenPrices[index] &&
                             Bars.ClosePrices[index - 1] > Bars.OpenPrices[index - 1] &&
                             Bars.ClosePrices[index] < Bars.OpenPrices[index - 1] &&
                             Bars.OpenPrices[index] > Bars.ClosePrices[index - 1];

            if (isBullish) return SetupType.BullishSweep;
            if (isBearish) return SetupType.BearishSweep;
            
            return SetupType.None;
        }

        // =========================================================================
        // CHART RENDERING (TAGS)
        // =========================================================================
        private void DrawSetupTag(int index, SetupType setup, CostBucket cost)
        {
            string objName = $"PA_Tag_{index}";
            Color tagColor = GetCostColor(cost);
            string routingRule = cost == CostBucket.Expensive ? "LIMIT ONLY" : "MARKET OK";

            if (setup == SetupType.BullishSweep)
            {
                double yPos = Bars.LowPrices[index] - (12 * Symbol.PipSize);
                var text = Chart.DrawText(objName, $"BULL\n{routingRule}", index, yPos, tagColor);
                text.VerticalAlignment = VerticalAlignment.Top;
                text.HorizontalAlignment = HorizontalAlignment.Center;
                text.FontSize = 9;
                text.IsBold = true;
            }
            else if (setup == SetupType.BearishSweep)
            {
                double yPos = Bars.HighPrices[index] + (12 * Symbol.PipSize);
                var text = Chart.DrawText(objName, $"BEAR\n{routingRule}", index, yPos, tagColor);
                text.VerticalAlignment = VerticalAlignment.Bottom;
                text.HorizontalAlignment = HorizontalAlignment.Center;
                text.FontSize = 9;
                text.IsBold = true;
            }
        }

        // =========================================================================
        // UI CONSTRUCTION & UPDATES
        // =========================================================================
        private void BuildControlPanel()
        {
            var stackPanel = new StackPanel { Orientation = Orientation.Vertical, Margin = 10 };

            // UI Header
            stackPanel.AddChild(new TextBlock 
            { 
                Text = "EXECUTION MICROSTRUCTURE", 
                ForegroundColor = Color.White, 
                FontWeight = FontWeight.Bold,
                Margin = new Thickness(0, 0, 0, 5) 
            });

            _spreadText = new TextBlock { ForegroundColor = Color.LightGray, Margin = new Thickness(0, 2, 0, 2) };
            _costBucketText = new TextBlock { ForegroundColor = Color.White, FontWeight = FontWeight.Bold };
            _executionText = new TextBlock { ForegroundColor = Color.White, Margin = new Thickness(0, 2, 0, 0) };

            stackPanel.AddChild(_spreadText);
            stackPanel.AddChild(_costBucketText);
            stackPanel.AddChild(_executionText);

            _hudContainer = new Border
            {
                BackgroundColor = Color.FromArgb(220, 25, 25, 25), // Semi-transparent dark gray
                BorderColor = Color.DimGray,
                BorderThickness = 1,
                CornerRadius = 3,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = "20 20 0 0",
                Child = stackPanel
            };

            Chart.AddControl(_hudContainer);
        }

        private void UpdateControlPanel(double currentSpread, CostBucket currentCost)
        {
            _spreadText.Text = $"Live Spread: {currentSpread} pips";
            _costBucketText.Text = $"Phase: {currentCost.ToString().ToUpper()}";
            _costBucketText.ForegroundColor = GetCostColor(currentCost);
            
            _executionText.Text = currentCost == CostBucket.Expensive 
                ? "ROUTING: LIMIT ORDERS REQUIRED" 
                : "ROUTING: MARKET ORDERS AUTHORIZED";
            _executionText.ForegroundColor = currentCost == CostBucket.Expensive ? Color.Crimson : Color.LimeGreen;
        }

        private Color GetCostColor(CostBucket cost)
        {
            switch (cost)
            {
                case CostBucket.Cheap: return Color.LimeGreen;
                case CostBucket.Normal: return Color.DodgerBlue;
                case CostBucket.Expensive: return Color.Crimson;
                default: return Color.White;
            }
        }

        // =========================================================================
        // CLEANUP
        // =========================================================================
        protected override void OnDestroy()
        {
            // Prevent memory leaks when changing timeframes
            if (_hudContainer != null)
                Chart.RemoveControl(_hudContainer);
        }
    }
}

Re: EURUSD journal: how cost tags changed my behavior

Posted: Fri Oct 02, 2026 9:52 am
by PTScalper
The next logical step for a professional workflow is extending this to generate automated journal data. By adding System.IO functionality inside the DrawSetupTag method, you can have the indicator silently append a row to a CSV file every time a setup triggers, logging the Server.Time, SetupType, and CostBucket. This automates the exact behavior you described in your original journal entry.

Re: EURUSD journal: how cost tags changed my behavior

Posted: Sun Oct 04, 2026 2:00 pm
by LondonNewsTrader
PTScalper wrote: This eliminates the need to adjust code every time daylight saving shifts or if you change brokers with different server offsets.
UTC fixes the broker offset part, but not the daylight saving part, because the sessions themselves move in UTC. The London open at 8:00 local time becomes 07:00 UTC during British Summer Time, roughly the last Sunday in March to the last Sunday in October, and the New York open shifts by the same hour on its own dates. With LonOpenHour = 8 and NyOpenHour = 13 in UTC, the expensive windows are an hour late for the summer months, so the tags will mark 08:00 to 08:15 UTC, after the open has already happened. An input for the local time and a conversion using TimeZoneInfo would handle both seasons.

The other thing I'd watch is consistency between live and historical tags. The last bar is evaluated with the real spread on each tick, but after a reload the same bar is evaluated with zero spread and only the time filter. A trade tagged EXPENSIVE live can therefore show as NORMAL the next day, which is awkward if the journal is built from screenshots. Writing the live tag to a file at bar close would give a permanent record.

Re: EURUSD journal: how cost tags changed my behavior

Posted: Mon Oct 05, 2026 8:03 am
by LondonScalper
That is exactly the split I was trying to name. The pattern itself was fine; the first fifteen minutes of the London open were not, once cost sat in its own column.

Before the tags I kept “fixing” the entry rules because the open blotter looked soft. After the tags I left the rules alone and tightened the spread gate instead. Win rate on the mid-morning version of the same setup barely moved. Expectancy did.

I still review R and outcome. I just refuse to grade an expensive open minute as if it were the same trade as a clean 09:40 print.

Re: EURUSD journal: how cost tags changed my behavior

Posted: Sat Oct 17, 2026 9:29 am
by FXS Prop Desk
The shift to limit orders in expensive conditions is a good observation. Worth noting that limit orders also carry an adverse selection cost: they tend to fill when price moves against you and miss when it moves your way. Tracking how often unfilled limits would have been winners helps measure whether the saved spread is worth the missed trades.

It may also be useful to compare the average fill quality of limit orders at different times of day, since the adverse selection cost often varies by session.

Re: EURUSD journal: how cost tags changed my behavior

Posted: Thu Oct 29, 2026 10:31 am
by Shadow Trader
Every trade starts at a deficit. The spread, the commission, and the likely slippage must be recovered before any profit appears. The sum is the trade's break-even cost.

For a scalper using a raw spread account, the numbers might be 0.3 pips of spread, 0.7 pips of commission equivalent, and 0.2 pips of slippage, a total of 1.2 pips. A strategy that targets three pips is giving up forty percent of its target to costs.

Looking at the cost as a percentage of the average winning trade makes the burden visible. Strategies with targets of ten pips or more have a more comfortable ratio than those with targets of two.

Reducing the cost has a direct effect on profit. Choosing sessions with tighter spreads, using limit orders when possible, and selecting pairs with better liquidity all help.

Another approach is to increase the average target, accepting fewer trades. Because costs are mostly fixed per trade, fewer and larger trades can improve net performance.

A helpful display is a small table with each cost component in pips, the sum, and the percentage of the average target. Keeping it in the journal and updating it monthly shows how changes in broker, account type, or session mix affect the drag. When the percentage rises above a third or so, the strategy needs either a larger target or a cheaper way to trade.

It is also worth separating fixed costs from variable ones. The commission is fixed, the spread varies by session, and slippage varies by order type and conditions. The variable parts are where the savings usually lie. Trading only when the spread is below a threshold, and using limit orders where practical, can reduce the average cost without changing anything about the strategy itself.

Seeing the numbers in one place often leads to a simple decision, such as dropping the worst hour of the day.

What is your all-in cost per trade as a percentage of your average winner?