Anhnga 5.8 - MT5 XAUUSD 60% PartialsI make it for Algoway
XAUUSDc - MT5
This Pine Script strategy, **Anhnga 5.8**, is a sophisticated trend-following system designed specifically for trading Gold (XAUUSD) and automated for use with MetaTrader 5 (MT5).
It combines momentum oscillators, trend filters, and a high-precision risk management system that includes **partial profit-taking** and **automatic breakeven.**
---
## 1. Core Trading Logic
The strategy enters a trade only when several "confluences" (conditions) align:
* **WaveTrend Oscillator:** It looks for a "cross" in the WaveTrend (WT) indicator. A Long signal occurs when WT crosses up from oversold levels; a Short signal occurs when it crosses down from overbought levels.
* **Trend Filter:** You can choose to only trade in the direction of the trend using two Moving Averages (Fast and Slow). For example, it will only Buy if the price is above both MAs.
* **Overextension Guard:** It calculates the distance between the price and the Moving Average using ATR (Average True Range). If the price has moved "too far, too fast," it skips the trade to avoid buying at the top or selling at the bottom.
* **Bollinger Band Filter:** It uses the BB Midline (Basis) as a gatekeeper. It only buys if the price is above the midline and only sells if it is below.
---
## 2. Advanced Risk Management
This is where the strategy stands out for professional use:
* **Partial Profit Taking (60%):** When the price reaches a "Partial Target" (halfway to your final TP), the strategy automatically closes **60% of your position**.
* **Automatic Breakeven:** Immediately after the partial profit is taken, the strategy moves the **Stop Loss (SL) to the entry price**. This ensures that the remaining 40% of the trade is "risk-free."
* **Reversal Guard:** This prevents "revenge trading." If a trade is closed, the script forces a cooldown period (default 5 bars) before you can enter a trade in the opposite direction.
* **Max SL Distance:** If the market is too volatile and the calculated Stop Loss is too wide (risking too many pips), the strategy will automatically skip that trade.
---
## 3. MT5 Automation (The "Bridge")
The strategy is coded to send specific text commands (Webhooks) to an automation bridge (like PineConnector or similar tools) to execute trades on **MetaTrader 5**.
| Command | Action in MT5 |
| --- | --- |
| `buy` / `sell` | Opens a position with your specific Lot size, SL, and TP. |
| `close` | Closes exactly 60% of the lot size when the first target is hit. |
| `closeall` | Flattens the entire position if a hard exit time or final TP/SL is hit. |
---
## 4. Key Settings to Watch
* **Trading Window:** Set to GMT+7 by default. It will only look for entries during your specified hours and will "Hard Flatten" (close everything) at a specific time (default 03:45 AM) to avoid overnight swaps or volatility.
* **Initial Capital:** Set to $50,000 for backtesting purposes.
* **Risk/Reward (RR):** Default is 1.0. This means if your SL is $5 away, your final TP will be $5 away.
---
## 5. Visual Guide on Chart
* **Cyan/White Lines:** Your Fast and Slow Moving Averages (Trend).
* **Red Line:** Your active Stop Loss.
* **Green Line:** Your final Take Profit.
* **Blue Line:** Your partial profit target (disappears once hit).
* **Background Colors:** Green zones show when you are allowed to trade; Red/Orange zones indicate the strategy is "resting" or outside trading hours.
**Would you like me to help you adjust the Risk:Reward ratios or modify the Partial Profit percentage (e.g., changing from 60% to 50%)?**
אסטרטגיית Pine Script®






















