X AI Gold
- Experts
- 버전: 3.30
- 업데이트됨: 4 7월 2026
- 활성화: 5
Dependent on Broker's Calendar data: If the broker's server does not fully update its Economic Calendar database.
SETUP:
1. Get API key: https://console.x.ai/
2. MT5 -> Tools -> Options -> Expert Advisors -> Allow WebRequest
Add URL: https://api.x.ai
3. Attach to XAUUSD chart
4. Set GrokApiKey in Inputs tab
👉 Main cause: The API Key you are configuring for the EA belongs to an x.AI account that has not been topped up or configured with a payment card to purchase Credits. Although newly created accounts usually receive trial credits (if available), this API Key currently has a zero balance, so it cannot perform further analysis.
2. Solution
You can fix this error in the following two ways:
Method 1: Top up your current x.AI account with Credits (Recommended)
Click directly on the link in your log: https://console.x.ai/ (or access the management page https://console.x.ai/).
Log in using the account containing your API Key.
Go to Billing / Funding.
Add an international payment card (Visa/Mastercard) and deposit a small amount (e.g., $5 or $10) into the account.
Once the account has an available balance (Credit balance > 0), the old API Key will automatically become active again without needing to change to a new key.
Method 2: Change to a different API Key (if you already have another account with funds available)
If you have another x.AI account that has been funded and is functioning normally, create a new API Key from that account and update it in the EA in one of two ways:
Method A (Configure directly on the EA): In the EA's input settings window on the MT5 chart, find the === GROK API === section and paste the new API Key into the GrokApiKey field.
Method B (Save to file): Leave the GrokApiKey field blank in the EA's input settings. Next, open the MT5 data folder (File -> Open Data Folder -> go to the MQL5/Files folder), open the grok_key.txt file (create a new one if it doesn't exist), paste the new API Key into it, and save it. The EA will automatically read the key from this file.
Guide Setup
1. The complete operating logic of Hybrid/Multi-Timeframe mode (GrokUseOnlyAPI = false).
When GrokUseOnlyAPI = false, the EA will operate as a 3-timeframe filter system (D1/H4/H1 or your chosen timeframe). The detailed order entry logic for this mode is as follows:
1. Analysis & Data Collection Cycle (OnInit/OnTick)
Indicator Initialization: The EA initializes 18 indicator handles on 2 timeframes, HTF (e.g., H4) and LTF (e.g., H1), including EMA 9/21/50/200, RSI, MACD, ATR, Bollinger Bands, and Stochastic.
Checking historical candlestick count: Before running the analysis, OnTick checks if the Terminal has loaded a minimum of 250 candlesticks for both HTF and LTF. If not, the EA will postpone the analysis and wait 30 seconds for MT5 to load more data.
1. Master Trend Update (EMA D1): The EA automatically retrieves candlestick data from the Master timeframe (GrokMasterTF - default is D1). Master Bias is filtered by comparing EMA50 and EMA200 on D1:
g_masterBias = "UPTREND" (if EMA50 > EMA200 and the closing price is above EMA50).
g_masterBias = "DOWNTREND" (if EMA50 < EMA200 and the closing price is below EMA50).
g_masterBias = "NEUTRAL" (other cases).
2. Create a Prompt combining Local Analysis to Send to Grok API
The EA collects all technical indicators from H4, H1, and SMC structure (BOS, CHoCH, Key Zones) and packages them into a highly detailed JSON prompt to send to the Grok API for decision-making.
After receiving feedback from Grok, the EA forwards the data through the 3-Timeframe Alignment Check filter (GrokCheck3TFAlignment).
3. 3-TF Filter Logic for Entry Decision (GrokCheck3TFAlignment)
This function compares the Master Bias (D1), the HTF trend analysis (H4), and the LTF signal (H1) returned by Grok:
🔹 Scenario 1: Absolute Trend Consensus (Full Alignment)
Decision: Enter the trade immediately with a Market order.
BUY Condition (TREND_BUY):
Grok's suggested signal: BUY
Master D1 Bias: UPTREND
Grok HTF analysis: UPTREND
Grok LTF analysis: BUY_SETUP or BUY
SELL Condition (TREND_SELL):
Grok's suggested signal: SELL
Master D1 Bias: DOWNTREND
Grok HTF analysis: DOWNTREND
Grok LTF analysis: SELL_SETUP or SELL
Reliability Requirement: Exceeds the user's GrokMinConfidence level (default 65%).
🔹 Scenario 2: Pullback Trade (Major D1 trend, Medium H4 trend countertrend)
If the user enables GrokAllowPullback = true (Allows pullback trading):
Meaning: Catching the retracement wave. Example: The long-term trend on D1 is upward, but H4 is undergoing a downward correction (Pullback). When a Buy signal appears on H1, reversing the trend back to the D1 trend → Place a BUY order.
BUY Condition (PULLBACK_BUY):
Grok's suggested signal: BUY
Master D1 Bias: UPTREND
Grok's HTF analysis: DOWNTREND (H4 Pullback)
Grok's LTF analysis: BUY_SETUP or BUY
SELL Condition (PULLBACK_SELL):
Grok's suggested signal: SELL
Master D1 Bias: DOWNTREND
Grok's HTF analysis: UPTREND (H4 Pullback)
Grok's LTF analysis: SELL_SETUP or SELL
Reliability Requirement (Very Important): Pullbacks carry higher risk, so the AI's reliability must meet a minimum of GrokPullbackMinConf (default setting is 75%, higher than the usual 65%).
🔹 Scenario 3: Master Neutral (D1 sideways)
Decision: Short-term trade based entirely on HTF + LTF consensus.
Conditions (HTF_LTF_TRADE):
Master D1 Bias: NEUTRAL
The Grok signal returned has: sig.alignment == "ALIGNED" (HTF and LTF agree in the same direction).
Reliability Requirement: GrokMinConfidence level (65%).
🔹 Scenario 4: Trend Conflict (CONFLICTED)
If it does not match any of the above scenarios, the system assesses this as a noisy area, assigns tradeType = "CONFLICTED" and rejects the order (in log: HOLD: 3-TF conflict [Master = ...]).
4. Order Management after successful entry
Trailing Stop: Update each tick according to the actual ATR of the LTF timeframe (g_market.ltf.atr14) instead of using the fallback point.
Multi-TP: If GrokUseMultiTP = true, the order is divided into 3 equal parts (TP1, TP2, TP3) and the Stop Loss is automatically moved to the Entry point (Breakeven) immediately after TP1 is successfully closed with profit.
2. Overall system logic for the "Only trade using Grok API" (GrokUseOnlyAPI = true) feature, both when running in Text-Only and Vision-Mode.
Below is a detailed logic evaluation report:
🔍 Candlestick cycle & order placement logic sequence (GrokUseOnlyAPI = true)
OnInit()
│
├── Skip indicator initialization (avoid wasting resources on VPS)
└── g_masterBias = "NONE" (do not calculate local HTF trend)
│
OnTick()
│
├── [Passed] Skip checking historical HTF/LTF candlestick count (avoid EA crashing due to missing old data)
└── Trailing Stop: g_market.ltf.atr14 = 0.0 → automatic fallback:
atrVal = GrokTrailingStopATR * Point * 100 (calculates trailing stop loss based on safe point)
│
GrokRunAnalysis()
│
├── Populates basic info: bid, ask, spread
├── Call GrokSendRequest()
│ │
│ ├── IF GrokUseVision = true:
│ │ ├── Capture chart PNG -> encode base64
│ │ └── Send Vision prompt + Image to API via model grok-2-vision-1212
│ │
│ └── IF GrokUseVision = false:
│ └── Send text-only prompt (SMC or Analyst)
│
GrokParseKVResponseContent()
│
├── Extract: DIRECTION, ENTRY, SL, TPs, CONFIDENCE
└── Extract new fields:
├── RISK_PERCENT (AI suggests risk, e.g., 0.5%)
└── PULLBACK_ENTRY (AI suggests waiting for a pullback to buy at a lower price)
│
Trading Block
│
├── IF PULLBACK_ENTRY > 0.0 (and Vision=true):
│ └── Place a LIMIT order (BuyLimit/SellLimit) at that pullback price
│
└── IF ENTRY has a value (or PULLBACK_ENTRY = 0.0):
└── Enter the trade directly using the Market order
* Lot Size: g_trade.Buy/Sell(lots, ...) with
lots = GrokCalcLot(..., sig.riskPercent)
→ effectiveRisk = min(AI proposed risk%, GrokRiskPercent input) (account protection)
🛡️ EA's Error and Fallback Tolerance
When GrokUseVision is disabled (Text-Only Mode):
The PULLBACK_ENTRY and RISK_PERCENT fields are parsed to 0.0.
The GrokCalcLot function receives the 0.0 parameter and automatically falls back to using the user-defined fixed GrokRiskPercent (e.g., 1.0%).
The GrokRunAnalysis block automatically runs in direct order mode using Market order as before.
No logic conflicts detected.
When Vision is enabled but screenshot capture fails:
The GrokCaptureChartBase64() function automatically frees memory, deletes junk images, and returns an empty string.
GrokSendRequest() detects the faulty image, prints a message to the Journal, and automatically falls back to the normal Text Prompt to send. The EA still runs smoothly, without crashing or interrupting analysis.
When GrokUseOnlyAPI = false (Hybrid/Multi-frame mode):
The entire mechanism for checking HTF/LTF history (250 candles), initializing MT5 Indicator handles, and checking the 3-TF trend filter still works normally as in previous v2.0 versions.
