如何让交易悬停提示显示EA名称?已尝试WindowExpertName()无效
Hey there, I see the issue you're running into—WindowExpertName() isn't doing what you expect because it's designed for a different purpose entirely. Let's break down how to get that custom "PipsTaker id 101" text showing up when you hover over your EA's orders.
Why WindowExpertName() Isn't Working
First, a quick clarification: WindowExpertName() only changes the name of the EA displayed in the chart window's title bar, not the text that appears when hovering over orders in the Trade tab. That's why your attempt didn't affect the order hover text—wrong tool for the job!
Solution 1: Set Custom Order Comments When Placing Trades
The right way to control that hover text is to define it directly in the order's comment when you send the trade. This works for both MT4 and MT5, and lets you specify the exact string you want.
MT4 Example Code
// When sending a buy order, include your custom text in the comment parameter int ticket = OrderSend( Symbol(), // Trading symbol OP_BUY, // Order type (buy) 0.1, // Volume Ask, // Entry price 3, // Slippage Ask - 50*Point, // Stop loss Ask + 50*Point, // Take profit "Buy order, placed by expert, PipsTaker id 101", // Your custom hover text 101, // EA's magic number (matches your "id 101") 0, // Expiration (none for market orders) Green // Order color );
MT5 Example Code
MT5 uses a trade request struct instead, but the idea is the same—populate the comment field with your desired text:
MqlTradeRequest request = {0}; MqlTradeResult result = {0}; // Configure the trade request request.action = TRADE_ACTION_DEAL; request.symbol = Symbol(); request.volume = 0.1; request.type = ORDER_TYPE_BUY; request.price = Ask; request.deviation = 3; request.sl = Ask - 50*Point; request.tp = Ask + 50*Point; request.comment = "Buy order, placed by expert, PipsTaker id 101"; // Custom text here request.magic = 101; // Magic number matches your "id 101" // Send the order if(!OrderSend(request, result)) { Print("Order failed with error code: ", GetLastError()); }
Once you implement this, hovering over the order in the Trade tab will display your exact custom string instead of the default expert name.
Solution 2: Rename Your EA File (Optional)
If you also want the default "Expert id X" label to use your custom name (as a backup), you can rename your EA's file to PipsTaker.ex4 (MT4) or PipsTaker.ex5 (MT5). This will make the default expert name show as "PipsTaker" instead of the original filename, but it won't include the "id 101" part—so combining this with Solution 1 is the best approach for full control.
内容的提问来源于stack exchange,提问作者Raphael Tunji

