IC Markets

Partial exits on M5 gold scalps without turning winners into scratches

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: 1114
Joined: Mon Jul 20, 2026 1:28 pm

Re: Partial exits on M5 gold scalps without turning winners into scratches

Post by PTScalper »

How to use this in TradingView:

Open a chart, click Pine Editor at the bottom, paste the code, and click Add to Chart.

Visual Assistant Mode: Turn off your strategy entries (or ignore the dummy trades). The blue and red dotted lines will dynamically draw exactly where your M5/M15 trailing stops should go in real time. Use these lines as a visual guide to adjust your MT4/cTrader stops manually.

Backtesting Mode: Replace the fast_ma and slow_ma dummy entry logic with your actual entry criteria (e.g., London sweep-and-reclaim). The Strategy Tester will now accurately simulate your $+1.5\text{R}$ winners and prove the mathematical expectancy of your partial framework.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 1114
Joined: Mon Jul 20, 2026 1:28 pm

Re: Partial exits on M5 gold scalps without turning winners into scratches

Post by PTScalper »

TradingView operates in a closed sandbox and cannot communicate directly with your broker. To route your Pine Script commands to MT4 or cTrader, you must use a third-party bridge service to translate TradingView webhooks into terminal executions.

1. The Middleware Bridge

You will need a specialized bridge service like PineConnector, CrossTrade, or TradingView.To. These platforms provide two necessary components:

A unique Webhook URL to paste into TradingView.

A receiver EA (MT4) or cBot (cTrader) that runs directly on your broker terminal to execute the incoming commands.

2. Formatting the Alert

Webhooks communicate via JSON (JavaScript Object Notation). You must update the strategy.exit() commands in your Pine Script to include the specific syntax required by your chosen bridge. For example, using PineConnector syntax, you append the alert_message parameter:

Code: Select all

// PineConnector syntax example for a 50% partial
string msg_partial = '{"Action": "ClosePartial", "Symbol": "XAUUSD", "Percentage": 50}'

// Pass the message into your exit order
strategy.exit("Partial", from_entry="Long", qty_percent=partial_pct, limit=target_price, stop=initial_sl, alert_message=msg_partial)
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
PTScalper
Site Admin
Posts: 1114
Joined: Mon Jul 20, 2026 1:28 pm

Re: Partial exits on M5 gold scalps without turning winners into scratches

Post by PTScalper »

You would write a separate JSON string for dynamically updating the trailing stop:

Code: Select all

string msg_trail = '{"Action": "UpdateSL", "Symbol": "XAUUSD", "SL": ' + str.tostring(current_sl) + '}'
3. Configuring the Webhook
Once your script contains the correct JSON strings:

Click the Alert icon on your TradingView chart.

Set the Condition to your specific Strategy.

In the "Message" box, type exactly this: {{strategy.order.alert_message}}. This placeholder tells TradingView to dynamically push the JSON string you assigned to that specific order.

Open the Notifications tab, check the Webhook URL box, and paste the URL provided by your bridge service.

4. The M5 Gold Reality Check
While automating visual strategies feels efficient, routing M5 XAUUSD scalps through a webhook introduces dangerous latency for a structural trader.

TradingView processes the price action.

TradingView fires the webhook over the internet to a middleware server.

The server formats the request and pings your MT4 EA.

MT4 finally sends the execution to your broker.

By the time a webhook moves your stop on an M5 gold chart, a volatility spike may have already wicked through it. If precise structural execution is the core of your edge, running the native MQL4/cTrader bots we built earlier directly on your broker terminal will drastically outperform any TradingView bridge.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Post Reply