Advertisement IC Markets

Desk rule: one metal or one yen theme, not both oversized

Discuss 1-minute to 15-minute price action setups, fading intraday momentum, key support/resistance zones, and proven short-term trading methodologies.
LondonScalper
Posts: 965
Joined: Sat Sep 05, 2026 7:54 am

Desk rule: one metal or one yen theme, not both oversized

Post by LondonScalper »

Desk rule: one metal theme or one yen theme -- not both oversized.

I used to run gold and USDJPY risk as if they were independent. On risk-off days they were not. Two "half" positions became one full thematic bet with correlated pain.

Rule
Pick a primary theme for the session. Secondary symbol only at reduced size, or flat. If gold is the story, yen scalp stays tiny or observational. If yen is the story, I do not also swing a full XAU ticket because the chart looks good.

This is risk budgeting, not prediction. Correlation estimates are wrong often enough that hard caps beat clever hedges.

How do you cap thematic overlap across metals and yen without freezing the desk?

I write the primary theme on the sticky at 07:00. Changing themes mid-session requires flattening first. Theme-hopping with overlapping risk is how correlated days become outsized days. One sentence of intent prevents a lot of clever doubling-up.
Recommended broker for automated trading & scalping IC Markets
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk rule: one metal or one yen theme, not both oversized

Post by PTScalper »

LondonScalper wrote: Mon Sep 14, 2026 10:23 pm Desk rule: one metal theme or one yen theme -- not both oversized.

I used to run gold and USDJPY risk as if they were independent. On risk-off days they were not. Two "half" positions became one full thematic bet with correlated pain.

Rule
Pick a primary theme for the session. Secondary symbol only at reduced size, or flat. If gold is the story, yen scalp stays tiny or observational. If yen is the story, I do not also swing a full XAU ticket because the chart looks good.

This is risk budgeting, not prediction. Correlation estimates are wrong often enough that hard caps beat clever hedges.

How do you cap thematic overlap across metals and yen without freezing the desk?

I write the primary theme on the sticky at 07:00. Changing themes mid-session requires flattening first. Theme-hopping with overlapping risk is how correlated days become outsized days. One sentence of intent prevents a lot of clever doubling-up.
Hi LondonScalper,

You cap thematic overlap across metals and yen by grouping them into a single "Safe Haven / US Real Rates" macro bucket and applying a hard capital limit to the bucket itself, rather than the individual tickers.

To do this without freezing the desk, you implement a Primary/Secondary fractional sizing matrix. The desk isn't banned from taking a setup in the secondary asset, but the ticket size is mechanically constrained so that the combined exposure never exceeds a single thematic VaR (Value at Risk) limit.

Here is how you structure it operationally:

The 1.25x Bucket Cap: If a standard full position is 1.0x, the combined exposure of XAU and JPY cannot exceed 1.25x.

The Intent Declaration: As you noted, the trader must declare the 1.0x primary driver at 07:00.

The Fractional Leash: The secondary asset is hard-capped at 0.25x. It exists strictly for observational scalping or capitalizing on extreme technical dislocations, not for swinging themes.

The "Wash" Penalty: If price action dictates that the secondary theme has actually become the dominant session driver, the trader must pay the "wash penalty"—flattening the current primary position entirely before the system/desk risk manager allows resizing the secondary up to 1.0x. This friction eliminates emotional, mid-session double-dipping.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk rule: one metal or one yen theme, not both oversized

Post by PTScalper »

Pine Script: The Digital Sticky Note

This Pine Script (v5) digitizes your 07:00 sticky note rule. It projects a HUD (Heads-Up Display) onto your chart. You set your primary theme in the indicator inputs at the start of the session, and it calculates your exact allowed ticket sizes, serving as a permanent visual anchor against overlapping risk.

Code: Select all

//@version=5
indicator("Desk Rule: Thematic Risk Budget", overlay=true)

// --- Inputs: The 07:00 Sticky Note ---
grp1 = "Session Intent (The Sticky Note)"
primaryTheme = input.string("Metals (XAU)", title="Primary Session Theme", options=["Metals (XAU)", "Yen (JPY)", "None (Risk Off)"], group=grp1)

grp2 = "Risk Parameters"
baseSize = input.float(1.0, title="Full Ticket Size (Lots/Contracts)", step=0.1, group=grp2)
secondaryCap = input.float(0.25, title="Secondary Scalp Multiplier", step=0.05, group=grp2, tooltip="Multiplier applied to the non-primary theme.")

// --- Position Sizing Logic ---
var float xauAllowed = 0.0
var float jpyAllowed = 0.0
var string xauRole = ""
var string jpyRole = ""

if primaryTheme == "Metals (XAU)"
    xauAllowed := baseSize
    jpyAllowed := baseSize * secondaryCap
    xauRole := "PRIMARY"
    jpyRole := "Secondary / Scalp"
else if primaryTheme == "Yen (JPY)"
    xauAllowed := baseSize * secondaryCap
    jpyAllowed := baseSize
    xauRole := "Secondary / Scalp"
    jpyRole := "PRIMARY"
else
    xauAllowed := 0.0
    jpyAllowed := 0.0
    xauRole := "FLAT"
    jpyRole := "FLAT"

// --- Visual Dashboard (HUD) ---
// Renders a cleanly formatted table in the top right corner
var table riskBoard = table.new(position.top_right, 3, 4, bgcolor=color.new(color.black, 15), border_width=1, border_color=color.new(color.gray, 50))

if barstate.islast
    // Table Headers
    table.cell(riskBoard, 0, 0, "Asset", text_color=color.white, text_weight=font.weight_bold, bgcolor=color.new(color.black, 0))
    table.cell(riskBoard, 1, 0, "Theme Role", text_color=color.white, text_weight=font.weight_bold, bgcolor=color.new(color.black, 0))
    table.cell(riskBoard, 2, 0, "Max Clip Size", text_color=color.white, text_weight=font.weight_bold, bgcolor=color.new(color.black, 0))

    // XAU Row
    xauColor = primaryTheme == "Metals (XAU)" ? color.new(color.yellow, 10) : color.new(color.gray, 40)
    table.cell(riskBoard, 0, 1, "Gold (XAU)", text_color=xauColor, text_weight=font.weight_bold)
    table.cell(riskBoard, 1, 1, xauRole, text_color=xauColor)
    table.cell(riskBoard, 2, 1, str.tostring(xauAllowed) + " Lots", text_color=xauColor)

    // JPY Row
    jpyColor = primaryTheme == "Yen (JPY)" ? color.new(color.aqua, 10) : color.new(color.gray, 40)
    table.cell(riskBoard, 0, 2, "Yen (JPY)", text_color=jpyColor, text_weight=font.weight_bold)
    table.cell(riskBoard, 1, 2, jpyRole, text_color=jpyColor)
    table.cell(riskBoard, 2, 2, str.tostring(jpyAllowed) + " Lots", text_color=jpyColor)

    // The Hard Rule Reminder
    table.cell(riskBoard, 0, 3, "DESK RULE: Mid-session theme changes require FLATTENING first.", text_color=color.new(color.red, 0), text_size=size.small, text_weight=font.weight_bold)
    table.merge_cells(riskBoard, 0, 3, 2, 3) // Spans the warning across the bottom of the table
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk rule: one metal or one yen theme, not both oversized

Post by PTScalper »

To upgrade this from a retail sizing rule to an institutional-grade risk framework, we need to move away from static "lot sizes" and implement Volatility-Adjusted Risk Budgeting.

Professional desks don't allocate "lots"; they allocate basis points of capital risk adjusted for current market volatility (ATR). If Gold is moving 3x faster than the Yen today, a static 0.25x lot multiplier will still result in skewed risk exposure.

Here is the "Pro" upgrade. This framework forces you to:

Allocate Capital, Not Lots: You set a maximum session risk (e.g., 1.5% of account equity).

Enforce Volatility Parity: It pulls real-time ATR for both assets to calculate exactly how many units you are allowed to trade based on a standard 1-ATR stop loss.

Strict Thematic Fencing: It calculates the exact max position size for the Primary and strictly caps the Secondary to a fractional allocation of your remaining risk budget.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk rule: one metal or one yen theme, not both oversized

Post by PTScalper »

The Institutional Thematic Risk Dashboard (Pine Script v5)

This script uses request.security to pull data for both your Gold and Yen tickers simultaneously, regardless of which chart you are currently viewing. It builds a live, dynamic risk matrix on your screen.

Code: Select all

//@version=5
indicator("Institutional Thematic Risk Matrix", overlay=true, max_lines_count=100)

// =========================================================================
// INPUTS: THE RISK DESK PARAMETERS
// =========================================================================
var string GRP_CONFIG = "1. Instrument Configuration"
tkrXAU = input.symbol("OANDA:XAUUSD", title="Gold Ticker", group=GRP_CONFIG)
tkrJPY = input.symbol("OANDA:USDJPY", title="Yen Ticker", group=GRP_CONFIG)

var string GRP_RISK = "2. Capital & Risk Allocation"
acctBalance = input.float(100000.0, title="Account Equity ($)", group=GRP_RISK)
maxSessionRisk = input.float(1.0, title="Max Session Risk (%)", step=0.1, group=GRP_RISK, tooltip="Total risk allowed across all correlated assets for this session.")
secondaryCap = input.float(15.0, title="Secondary Allocation Cap (%)", step=1.0, group=GRP_RISK, tooltip="Max percentage of the session risk budget allocated to the secondary theme.")

var string GRP_THEME = "3. The Session Intent (07:00 Fix)"
primaryTheme = input.string("XAU (Metals)", title="Primary Driver", options=["XAU (Metals)", "JPY (Rates)", "FLAT (Cash)"], group=GRP_THEME)

var string GRP_VOL = "4. Volatility Parity Settings"
atrLength = input.int(14, title="ATR Length", group=GRP_VOL)
stopMultiplier = input.float(1.5, title="Stop Distance (ATR Multiplier)", step=0.1, group=GRP_VOL)

// =========================================================================
// CALCULATIONS: VOLATILITY & CAPITAL ALLOCATION
// =========================================================================
// Fetch ATR for both instruments to ensure volatility parity
[xauClose, xauAtr] = request.security(tkrXAU, timeframe.period, [close, ta.atr(atrLength)])
[jpyClose, jpyAtr] = request.security(tkrJPY, timeframe.period, [close, ta.atr(atrLength)])

// Calculate Risk Budgets (in Dollars)
float totalRiskCapital = acctBalance * (maxSessionRisk / 100)
float primaryRiskCapital = totalRiskCapital * (1 - (secondaryCap / 100))
float secondaryRiskCapital = totalRiskCapital * (secondaryCap / 100)

// Assign Risk Capital based on the 07:00 Sticky Note
float xauCapitalLimit = 0.0
float jpyCapitalLimit = 0.0
string xauStatus = ""
string jpyStatus = ""

if primaryTheme == "XAU (Metals)"
    xauCapitalLimit := primaryRiskCapital
    jpyCapitalLimit := secondaryRiskCapital
    xauStatus := "DOMINANT"
    jpyStatus := "SCALP ONLY"
else if primaryTheme == "JPY (Rates)"
    xauCapitalLimit := secondaryRiskCapital
    jpyCapitalLimit := primaryRiskCapital
    xauStatus := "SCALP ONLY"
    jpyStatus := "DOMINANT"
else
    xauCapitalLimit := 0.0
    jpyCapitalLimit := 0.0
    xauStatus := "LOCKED"
    jpyStatus := "LOCKED"

// Calculate Position Sizing (Units) based on Volatility (Stop Distance)
// Formula: Risk $ / (Stop Distance in Price terms)
float xauStopDist = xauAtr * stopMultiplier
float jpyStopDist = jpyAtr * stopMultiplier

float xauMaxUnits = xauCapitalLimit / xauStopDist
float jpyMaxUnits = jpyCapitalLimit / jpyStopDist

// =========================================================================
// HUD RENDERING: THE RISK MANAGER UI
// =========================================================================
// Institutional styling: Dark backgrounds, monospaced text, strict colors
var table riskHUD = table.new(position.top_right, 4, 5, bgcolor=color.rgb(15, 15, 15, 10), border_width=1, border_color=color.rgb(50, 50, 50, 0))

if barstate.islast
    // Headers
    table.cell(riskHUD, 0, 0, "INSTRUMENT", text_color=color.gray, text_size=size.small, bgcolor=color.black)
    table.cell(riskHUD, 1, 0, "THEME ROLE", text_color=color.gray, text_size=size.small, bgcolor=color.black)
    table.cell(riskHUD, 2, 0, "CAPITAL AT RISK", text_color=color.gray, text_size=size.small, bgcolor=color.black)
    table.cell(riskHUD, 3, 0, "MAX SIZE (UNITS)", text_color=color.gray, text_size=size.small, bgcolor=color.black)

    // XAU Row
    c_xau = primaryTheme == "XAU (Metals)" ? color.rgb(255, 204, 0) : color.gray
    table.cell(riskHUD, 0, 1, tkrXAU, text_color=c_xau, text_weight=font.weight_bold)
    table.cell(riskHUD, 1, 1, xauStatus, text_color=c_xau, text_size=size.small)
    table.cell(riskHUD, 2, 1, "$" + str.tostring(math.round(xauCapitalLimit)), text_color=c_xau)
    table.cell(riskHUD, 3, 1, str.tostring(math.round(xauMaxUnits, 2)), text_color=c_xau, text_weight=font.weight_bold)

    // JPY Row
    c_jpy = primaryTheme == "JPY (Rates)" ? color.rgb(0, 204, 255) : color.gray
    table.cell(riskHUD, 0, 2, tkrJPY, text_color=c_jpy, text_weight=font.weight_bold)
    table.cell(riskHUD, 1, 2, jpyStatus, text_color=c_jpy, text_size=size.small)
    table.cell(riskHUD, 2, 2, "$" + str.tostring(math.round(jpyCapitalLimit)), text_color=c_jpy)
    table.cell(riskHUD, 3, 2, str.tostring(math.round(jpyMaxUnits, 2)), text_color=c_jpy, text_weight=font.weight_bold)

    // Total Exposure Row
    table.cell(riskHUD, 0, 3, "SESSION TOTAL", text_color=color.white, text_size=size.small, bgcolor=color.rgb(30, 30, 30))
    table.cell(riskHUD, 1, 3, "BUDGET: " + str.tostring(maxSessionRisk) + "%", text_color=color.white, text_size=size.small, bgcolor=color.rgb(30, 30, 30))
    table.cell(riskHUD, 2, 3, "$" + str.tostring(math.round(xauCapitalLimit + jpyCapitalLimit)), text_color=color.white, text_weight=font.weight_bold, bgcolor=color.rgb(30, 30, 30))
    table.cell(riskHUD, 3, 3, "N/A", text_color=color.gray, text_size=size.small, bgcolor=color.rgb(30, 30, 30))

    // Operational Directive
    table.cell(riskHUD, 0, 4, "PROTOCOL: FLAT ENTIRE BOOK BEFORE CHANGING PRIMARY THEME.", text_color=color.rgb(255, 50, 50), text_size=size.small, text_weight=font.weight_bold)
    table.merge_cells(riskHUD, 0, 4, 3, 4)
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk rule: one metal or one yen theme, not both oversized

Post by PTScalper »

How to Trade with This Pro Framework

The 07:00 Fix: Before the London/NY crossover, you evaluate the macro narrative. Are US real rates driving the market, or is it a localized safe-haven bid? You set the Primary Driver in the indicator inputs.

Dynamic Volatility Sizing: The script automatically looks at the 14-period ATR for both Gold and Yen. If Gold is highly volatile today, it will automatically reduce your allowed position size so that a standard 1.5 * ATR stop-loss mathematically equates to your specific dollar risk limit.

The 15% Scalp Fencing: Notice the Secondary Allocation Cap is set to a strict 15% default. If you are swinging Gold, the script only permits 15% of your total session risk to touch the Yen. This acts as a circuit breaker against "accidental" correlated blowouts while still leaving room for high-probability scalps.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk rule: one metal or one yen theme, not both oversized

Post by PTScalper »

Here are the institutional-grade MQL4 and MQL5 indicator versions of the Thematic Risk Dashboard.

Both scripts calculate exact broker-standard lot sizes (accounting for tick values, contract sizes, and real-time ATR volatility) and project a persistent HUD onto your chart.

1. MetaTrader 4 Version (MQL4)
Save this in MetaEditor under Indicators/ThematicRiskMatrix.mq4.

Code: Select all

//+------------------------------------------------------------------+
//|                                     ThematicRiskMatrix_MT4.mq4   |
//|                        Desk Rule: Thematic Overlap Risk Budget   |
//+------------------------------------------------------------------+
#property copyright "Trading Desk"
#property link      ""
#property version   "1.00"
#property indicator_chart_window

enum ENUM_PRIMARY_THEME
{
   THEME_XAU,  // Metals (XAU)
   THEME_JPY,  // Rates / Yen (JPY)
   THEME_FLAT  // FLAT (Cash Only)
};

//--- Inputs
input string             InpHeader1        = "=== Instruments ===";       // --- Instruments ---
input string             InpSymbolXAU      = "XAUUSD";                   // Gold Symbol
input string             InpSymbolJPY      = "USDJPY";                   // Yen Symbol

input string             InpHeader2        = "=== Capital & Risk ===";    // --- Capital & Risk ---
input double             InpSessionRiskPct = 1.0;                        // Max Session Risk (% Equity)
input double             InpSecondaryCapPct= 15.0;                       // Secondary Allocation Cap (%)

input string             InpHeader3        = "=== The 07:00 Fix ===";     // --- The 07:00 Fix ---
input ENUM_PRIMARY_THEME InpPrimaryTheme   = THEME_XAU;                  // Primary Driver

input string             InpHeader4        = "=== Volatility Model ===";  // --- Volatility Model ---
input int                InpAtrPeriod      = 14;                         // ATR Period
input double             InpAtrMultiplier  = 1.5;                        // Stop Distance (ATR Multiplier)

//--- Global Variables
string g_prefix = "TRM_";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   EventSetTimer(2);
   UpdateHUD();
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   EventKillTimer();
   ObjectsDeleteAll(0, g_prefix);
   ChartRedraw();
}

//+------------------------------------------------------------------+
//| Timer event to refresh dashboard                                 |
//+------------------------------------------------------------------+
void OnTimer()
{
   UpdateHUD();
}

//+------------------------------------------------------------------+
//| OnCalculate                                                      |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   UpdateHUD();
   return(rates_total);
}

//+------------------------------------------------------------------+
//| Calculate allowed lots based on risk $ and ATR stop distance    |
//+------------------------------------------------------------------+
double CalculateLots(string symbol, double riskCapital, double atrDistance)
{
   if(riskCapital <= 0.0 || atrDistance <= 0.0) return 0.0;
   
   double tickSize  = MarketInfo(symbol, MODE_TICKSIZE);
   double tickValue = MarketInfo(symbol, MODE_TICKVALUE);
   double minLot    = MarketInfo(symbol, MODE_MINLOT);
   double maxLot    = MarketInfo(symbol, MODE_MAXLOT);
   double lotStep   = MarketInfo(symbol, MODE_LOTSTEP);
   
   if(tickSize == 0.0 || tickValue == 0.0) return 0.0;
   
   double lossPerLot = (atrDistance / tickSize) * tickValue;
   if(lossPerLot <= 0.0) return 0.0;
   
   double rawLots = riskCapital / lossPerLot;
   double steppedLots = MathFloor(rawLots / lotStep) * lotStep;
   
   return MathMin(maxLot, MathMax(minLot, steppedLots));
}

//+------------------------------------------------------------------+
//| Render Institutional HUD Label                                   |
//+------------------------------------------------------------------+
void CreateLabel(string name, string text, int x, int y, color clr, int fontSize = 9, bool isBold = false)
{
   string objName = g_prefix + name;
   if(ObjectFind(0, objName) < 0)
   {
      ObjectCreate(0, objName, OBJ_LABEL, 0, 0, 0);
      ObjectSetInteger(0, objName, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
      ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
      ObjectSetString(0, objName, OBJPROP_FONT, "Consolas");
   }
   ObjectSetInteger(0, objName, OBJPROP_XDISTANCE, x);
   ObjectSetInteger(0, objName, OBJPROP_YDISTANCE, y);
   ObjectSetString(0, objName, OBJPROP_TEXT, text);
   ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
   ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, fontSize);
}

//+------------------------------------------------------------------+
//| Main Dashboard Logic                                             |
//+------------------------------------------------------------------+
void UpdateHUD()
{
   double equity = AccountEquity();
   double totalRiskCapital = equity * (InpSessionRiskPct / 100.0);
   double primaryCap       = totalRiskCapital * (1.0 - (InpSecondaryCapPct / 100.0));
   double secondaryCap     = totalRiskCapital * (InpSecondaryCapPct / 100.0);
   
   double xauRisk = 0.0, jpyRisk = 0.0;
   string xauRole = "FLAT", jpyRole = "FLAT";
   color  xauClr  = clrGray, jpyClr  = clrGray;
   
   if(InpPrimaryTheme == THEME_XAU)
   {
      xauRisk = primaryCap;   xauRole = "DOMINANT";   xauClr = clrGold;
      jpyRisk = secondaryCap; jpyRole = "SCALP ONLY"; jpyClr = clrDeepSkyBlue;
   }
   else if(InpPrimaryTheme == THEME_JPY)
   {
      jpyRisk = primaryCap;   jpyRole = "DOMINANT";   jpyClr = clrDeepSkyBlue;
      xauRisk = secondaryCap; xauRole = "SCALP ONLY"; xauClr = clrGold;
   }
   
   // Real-time ATR readings
   double xauAtr = iATR(InpSymbolXAU, Period(), InpAtrPeriod, 0) * InpAtrMultiplier;
   double jpyAtr = iATR(InpSymbolJPY, Period(), InpAtrPeriod, 0) * InpAtrMultiplier;
   
   double xauLots = CalculateLots(InpSymbolXAU, xauRisk, xauAtr);
   double jpyLots = CalculateLots(InpSymbolJPY, jpyRisk, jpyAtr);
   
   // Draw HUD Table
   int x = 20;
   int y = 25;
   int rowSpacing = 18;
   
   CreateLabel("H1", "=== THEMATIC RISK DESK (07:00 FIX) ===", x, y, clrWhite, 10, true);
   y += rowSpacing + 4;
   
   CreateLabel("XAU_LINE", StringFormat("%-8s | %-10s | Risk: $%4.0f | Max: %.2f Lots", 
               InpSymbolXAU, xauRole, xauRisk, xauLots), x, y, xauClr, 9);
   y += rowSpacing;
   
   CreateLabel("JPY_LINE", StringFormat("%-8s | %-10s | Risk: $%4.0f | Max: %.2f Lots", 
               InpSymbolJPY, jpyRole, jpyRisk, jpyLots), x, y, jpyClr, 9);
   y += rowSpacing;
   
   CreateLabel("TOT_LINE", StringFormat("TOTAL RISK: $%4.0f / %3.1f%% Equity (Balance: $%.0f)", 
               (xauRisk + jpyRisk), InpSessionRiskPct, equity), x, y, clrLightGray, 8);
   y += rowSpacing + 4;
   
   CreateLabel("RULE", "RULE: Flatten all themes before changing primary driver.", x, y, clrCrimson, 8);
   
   ChartRedraw();
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk rule: one metal or one yen theme, not both oversized

Post by PTScalper »

2. MetaTrader 5 Version (MQL5)

Save this in MetaEditor under Indicators/ThematicRiskMatrix.mq5.

Code: Select all

//+------------------------------------------------------------------+
//|                                     ThematicRiskMatrix_MT5.mq5   |
//|                        Desk Rule: Thematic Overlap Risk Budget   |
//+------------------------------------------------------------------+
#property copyright "Trading Desk"
#property link      ""
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 0

enum ENUM_PRIMARY_THEME
{
   THEME_XAU,  // Metals (XAU)
   THEME_JPY,  // Rates / Yen (JPY)
   THEME_FLAT  // FLAT (Cash Only)
};

//--- Inputs
input group "=== Instruments ==="
input string             InpSymbolXAU      = "XAUUSD";                   // Gold Symbol
input string             InpSymbolJPY      = "USDJPY";                   // Yen Symbol

input group "=== Capital & Risk ==="
input double             InpSessionRiskPct = 1.0;                        // Max Session Risk (% Equity)
input double             InpSecondaryCapPct= 15.0;                       // Secondary Allocation Cap (%)

input group "=== The 07:00 Fix ==="
input ENUM_PRIMARY_THEME InpPrimaryTheme   = THEME_XAU;                  // Primary Driver

input group "=== Volatility Model ==="
input int                InpAtrPeriod      = 14;                         // ATR Period
input double             InpAtrMultiplier  = 1.5;                        // Stop Distance (ATR Multiplier)

//--- Handles & Globals
int    g_handleAtrXAU = INVALID_HANDLE;
int    g_handleAtrJPY = INVALID_HANDLE;
string g_prefix       = "TRM_";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   g_handleAtrXAU = iATR(InpSymbolXAU, _Period, InpAtrPeriod);
   g_handleAtrJPY = iATR(InpSymbolJPY, _Period, InpAtrPeriod);
   
   EventSetTimer(2);
   UpdateHUD();
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   EventKillTimer();
   IndicatorRelease(g_handleAtrXAU);
   IndicatorRelease(g_handleAtrJPY);
   ObjectsDeleteAll(0, g_prefix);
   ChartRedraw();
}

//+------------------------------------------------------------------+
//| Timer event to refresh dashboard                                 |
//+------------------------------------------------------------------+
void OnTimer()
{
   UpdateHUD();
}

//+------------------------------------------------------------------+
//| OnCalculate                                                      |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   UpdateHUD();
   return(rates_total);
}

//+------------------------------------------------------------------+
//| Calculate allowed lots based on tick value & ATR distance        |
//+------------------------------------------------------------------+
double CalculateLots(string symbol, double riskCapital, double atrDistance)
{
   if(riskCapital <= 0.0 || atrDistance <= 0.0) return 0.0;
   
   double tickSize  = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
   double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
   double minLot    = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN);
   double maxLot    = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX);
   double lotStep   = SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP);
   
   if(tickSize == 0.0 || tickValue == 0.0 || lotStep == 0.0) return 0.0;
   
   double lossPerLot = (atrDistance / tickSize) * tickValue;
   if(lossPerLot <= 0.0) return 0.0;
   
   double rawLots = riskCapital / lossPerLot;
   double steppedLots = MathFloor(rawLots / lotStep) * lotStep;
   
   return MathMin(maxLot, MathMax(minLot, steppedLots));
}

//+------------------------------------------------------------------+
//| Render Institutional HUD Label                                   |
//+------------------------------------------------------------------+
void CreateLabel(string name, string text, int x, int y, color clr, int fontSize = 9)
{
   string objName = g_prefix + name;
   if(ObjectFind(0, objName) < 0)
   {
      ObjectCreate(0, objName, OBJ_LABEL, 0, 0, 0);
      ObjectSetInteger(0, objName, OBJPROP_CORNER, CORNER_RIGHT_UPPER);
      ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_RIGHT_UPPER);
      ObjectSetString(0, objName, OBJPROP_FONT, "Consolas");
   }
   ObjectSetInteger(0, objName, OBJPROP_XDISTANCE, x);
   ObjectSetInteger(0, objName, OBJPROP_YDISTANCE, y);
   ObjectSetString(0, objName, OBJPROP_TEXT, text);
   ObjectSetInteger(0, objName, OBJPROP_COLOR, clr);
   ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, fontSize);
}

//+------------------------------------------------------------------+
//| Main Dashboard Logic                                             |
//+------------------------------------------------------------------+
void UpdateHUD()
{
   double equity = AccountInfoDouble(ACCOUNT_EQUITY);
   double totalRiskCapital = equity * (InpSessionRiskPct / 100.0);
   double primaryCap       = totalRiskCapital * (1.0 - (InpSecondaryCapPct / 100.0));
   double secondaryCap     = totalRiskCapital * (InpSecondaryCapPct / 100.0);
   
   double xauRisk = 0.0, jpyRisk = 0.0;
   string xauRole = "FLAT", jpyRole = "FLAT";
   color  xauClr  = clrGray, jpyClr  = clrGray;
   
   if(InpPrimaryTheme == THEME_XAU)
   {
      xauRisk = primaryCap;   xauRole = "DOMINANT";   xauClr = clrGold;
      jpyRisk = secondaryCap; jpyRole = "SCALP ONLY"; jpyClr = clrDeepSkyBlue;
   }
   else if(InpPrimaryTheme == THEME_JPY)
   {
      jpyRisk = primaryCap;   jpyRole = "DOMINANT";   jpyClr = clrDeepSkyBlue;
      xauRisk = secondaryCap; xauRole = "SCALP ONLY"; xauClr = clrGold;
   }
   
   // Read ATR buffer values
   double atrBufXAU[1], atrBufJPY[1];
   double xauAtr = 0.0, jpyAtr = 0.0;
   
   if(CopyBuffer(g_handleAtrXAU, 0, 0, 1, atrBufXAU) > 0)
      xauAtr = atrBufXAU[0] * InpAtrMultiplier;
   if(CopyBuffer(g_handleAtrJPY, 0, 0, 1, atrBufJPY) > 0)
      jpyAtr = atrBufJPY[0] * InpAtrMultiplier;
   
   double xauLots = CalculateLots(InpSymbolXAU, xauRisk, xauAtr);
   double jpyLots = CalculateLots(InpSymbolJPY, jpyRisk, jpyAtr);
   
   // Draw HUD Table
   int x = 20;
   int y = 25;
   int rowSpacing = 18;
   
   CreateLabel("H1", "=== THEMATIC RISK DESK (07:00 FIX) ===", x, y, clrWhite, 10);
   y += rowSpacing + 4;
   
   CreateLabel("XAU_LINE", StringFormat("%-8s | %-10s | Risk: $%4.0f | Max: %.2f Lots", 
               InpSymbolXAU, xauRole, xauRisk, xauLots), x, y, xauClr, 9);
   y += rowSpacing;
   
   CreateLabel("JPY_LINE", StringFormat("%-8s | %-10s | Risk: $%4.0f | Max: %.2f Lots", 
               InpSymbolJPY, jpyRole, jpyRisk, jpyLots), x, y, jpyClr, 9);
   y += rowSpacing;
   
   CreateLabel("TOT_LINE", StringFormat("TOTAL RISK: $%4.0f / %3.1f%% Equity (Balance: $%.0f)", 
               (xauRisk + jpyRisk), InpSessionRiskPct, equity), x, y, clrLightGray, 8);
   y += rowSpacing + 4;
   
   CreateLabel("RULE", "RULE: Flatten all themes before changing primary driver.", x, y, clrCrimson, 8);
   
   ChartRedraw();
}
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk rule: one metal or one yen theme, not both oversized

Post by PTScalper »

Key Operational Features in Both Scripts

Broker Contract Conversion: Rather than guessing lot values, both scripts pull SYMBOL_TRADE_TICK_VALUE and SYMBOL_TRADE_TICK_SIZE. Whether your broker calculates XAU as 100 oz or 50 oz, the lot output strictly preserves your exact dollar cap.

Vol Parity Stop Engine: Both scripts use real-time 1.5 * ATR distances to size lots. If London volatility spikes Gold's ATR, your Gold lot size shrinks automatically to keep dollar loss constant.

Timer Decoupling (OnTimer): Even if the current chart is slow or off-market (e.g., viewing on a low-liquidity weekend/session), the HUD refreshes every 2 seconds via EventSetTimer.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 7821
Joined: Mon Jul 20, 2026 1:28 pm

Re: Desk rule: one metal or one yen theme, not both oversized

Post by PTScalper »

Here is the institutional-grade cTrader (cAlgo) implementation of the Thematic Risk Dashboard.

Unlike MT4/MT5 where you are forced to draw clumsy text labels, cTrader has a full modern UI framework (WPF-based). This script utilizes cTrader's native Grid and TextBlock components to render a clean, professional dashboard that updates tick-by-tick without lagging the chart.

The cTrader Custom Indicator (C#)

1.) Open cTrader Automate.

2.) Click New Indicator.

3.) Name it ThematicRiskMatrix.

4.) Replace the default code with the C# script below and build it.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Post Reply