Dear MQL5 Community
-
The Issue:
-
I am encountering persistent warnings related to "implicit conversion from 'number' to 'string'" during compilation, particularly in debug or logging operations using Print() and StringFormat() .
-
Here is an example of where the warning occurs:
mql5LogDebug(StringFormat("Trigger Order Found: Ticket = %llu | MagicNumber = %d | Type = %s | LotSize = %.2f", TrackedTicket, TrackedMagicNumber, orderType == POSITION_TYPE_BUY ? "Buy" : "Sell", lotSize));
-
The warning frequently appears whenever variables such as TrackedTicket (of type ulong ) or TrackedMagicNumber (of type int ) are used in concatenations or formatting.
-
-
Please edit your msg and re add your code via the CODE S button.
If you had done a simple search of online documents on this website, you would have found the solution on the first page. All numbers, integers and doubles, need to be converted to string. You will find the syntax code in the mentioned search results from "documents" link on left side of the search results page.
-
I edited your (original) post and used the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Messages Editor
Forum rules and recommendations - General - MQL5 programming forum (2023) -
if (ticket > 0 && PositionSelect(ticket))
Perhaps you should read the manual, or press F1 in the editor. PositionSelect - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.Perhaps you meant PositionSelectByTicket
-
I edited your (original) post and used the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Messages Editor
Forum rules and recommendations - General - MQL5 programming forum (2023) -
x
//+------------------------------------------------------------------+ //| EA to Manage and Monitor Templates | //+------------------------------------------------------------------+ #property strict // User Inputs input string TradeSymbol = "XAUUSDm"; // User-specified symbol input ENUM_TIMEFRAMES TradeTimeFrame = PERIOD_M1; // User-specified time frame (dropdown) input double TriggerLotSize = 1.0; // Lot size threshold to trigger action input string BuyTemplate = "BUY_Transmitter_template.tpl"; // Buy template name input string SellTemplate = "SELL_Transmitter_template.tpl"; // Sell template name input bool DebugMode = true; // Enable/Disable debug logging // Global Variables ulong TrackedTicket = 0; // Ticket to track int TrackedMagicNumber = -1; // Magic number for the tracked order ENUM_POSITION_TYPE TrackedOrderType; // Buy or Sell type bool TemplateLoaded = false; // Tracks whether the template is loaded long OpenedChartID = 0; // Store the opened chart ID for better management //+------------------------------------------------------------------+ //| Debug Helper Function | //+------------------------------------------------------------------+ void LogDebug(string message) { if (DebugMode) Print(message); } //+------------------------------------------------------------------+ //| Find and Mark Trigger Order | //+------------------------------------------------------------------+ bool FindTriggerOrder() { int totalOrders = PositionsTotal(); for (int i = 0; i < totalOrders; i++) { ulong ticket = PositionGetTicket(i); if (ticket > 0 && PositionSelect(ticket)) { double lotSize = PositionGetDouble(POSITION_VOLUME); int magicNumber = (int)PositionGetInteger(POSITION_MAGIC); ENUM_POSITION_TYPE orderType = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); if (lotSize >= TriggerLotSize) { TrackedTicket = ticket; TrackedMagicNumber = magicNumber; TrackedOrderType = orderType; // Fix the implicit conversion warnings using proper conversion functions string ticketStr = IntegerToString(TrackedTicket); string magicStr = IntegerToString(TrackedMagicNumber); string typeStr = (orderType == POSITION_TYPE_BUY) ? "Buy" : "Sell"; string lotStr = DoubleToString(lotSize, 2); LogDebug("Trigger Order Found: Ticket = " + ticketStr + " | MagicNumber = " + magicStr + " | Type = " + typeStr + " | LotSize = " + lotStr); return true; } } } return false; } //+------------------------------------------------------------------+ //| Open New Chart with Template | //+------------------------------------------------------------------+ void OpenChartWithTemplate(string templateName) { OpenedChartID = ChartOpen(TradeSymbol, TradeTimeFrame); // Open specified symbol and time frame if (OpenedChartID > 0) { if (ChartApplyTemplate(OpenedChartID, templateName)) { ChartSetInteger(OpenedChartID, CHART_IS_MAXIMIZED, 1); // Maximize the chart // Fix string formatting to avoid implicit conversion string tfStr = EnumToString(TradeTimeFrame); LogDebug("Template applied successfully: " + templateName + " on " + TradeSymbol + " (" + tfStr + ")"); TemplateLoaded = true; } else { string tfStr = EnumToString(TradeTimeFrame); Print("Failed to apply template: " + templateName + " on " + TradeSymbol + " (" + tfStr + ")"); } } else { string tfStr = EnumToString(TradeTimeFrame); Print("Failed to open " + TradeSymbol + " (" + tfStr + ") chart."); } } //+------------------------------------------------------------------+ //| Close Chart Running Specific EA | //+------------------------------------------------------------------+ void CloseChartWithEA() { int totalOrders = PositionsTotal(); bool positionFound = false; for (int i = 0; i < totalOrders; i++) { ulong ticket = PositionGetTicket(i); if (ticket > 0 && PositionSelect(ticket)) { if (ticket == TrackedTicket) { positionFound = true; double tpPrice = PositionGetDouble(POSITION_TP); ENUM_POSITION_TYPE orderType = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); if (tpPrice > 0) { if ((orderType == POSITION_TYPE_BUY && SymbolInfoDouble(TradeSymbol, SYMBOL_BID) >= tpPrice) || (orderType == POSITION_TYPE_SELL && SymbolInfoDouble(TradeSymbol, SYMBOL_ASK) <= tpPrice)) { // Only close the chart we opened if (OpenedChartID > 0 && ChartClose(OpenedChartID)) { // Fix string formatting string magicStr = IntegerToString(TrackedMagicNumber); string tfStr = EnumToString(TradeTimeFrame); LogDebug("Chart closed for MagicNumber: " + magicStr + " on " + TradeSymbol + " (" + tfStr + ")"); ResetTracking(); } else { string magicStr = IntegerToString(TrackedMagicNumber); string tfStr = EnumToString(TradeTimeFrame); Print("Failed to close chart for MagicNumber: " + magicStr + " on " + TradeSymbol + " (" + tfStr + ")"); } return; } } break; } } } // If the tracked position no longer exists if (!positionFound && TrackedTicket > 0) { LogDebug("Tracked position no longer exists. Closing chart and resetting tracking."); if (OpenedChartID > 0) { ChartClose(OpenedChartID); } ResetTracking(); } } //+------------------------------------------------------------------+ //| Reset Tracking Variables | //+------------------------------------------------------------------+ void ResetTracking() { TrackedTicket = 0; TrackedMagicNumber = -1; TemplateLoaded = false; OpenedChartID = 0; } //+------------------------------------------------------------------+ //| Main Execution Function | //+------------------------------------------------------------------+ void OnTick() { // Ensure the EA runs only for the user-defined symbol and time frame if (Symbol() != TradeSymbol || Period() != TradeTimeFrame) return; // Main logic if (TrackedMagicNumber == -1) { if (FindTriggerOrder()) { // Open the appropriate template if (TrackedOrderType == POSITION_TYPE_BUY) { OpenChartWithTemplate(BuyTemplate); } else if (TrackedOrderType == POSITION_TYPE_SELL) { OpenChartWithTemplate(SellTemplate); } } } else { // Check if the tracked order hit TP and close the template chart CloseChartWithEA(); } }
Worth a try :) .
Thank you for your response, but still same warning message.
'EA CONTROLLER TEST.mq5' 1
implicit conversion from 'number' to 'string' EA CONTROLLER TEST.mq5 39 42
implicit conversion from 'number' to 'string' EA CONTROLLER TEST.mq5 111 42
code generated 1
0 errors, 2 warnings, 569 msec elapsed, cpu='X64 Regular' 3
Thank you for your response, but still same warning message.
'EA CONTROLLER TEST.mq5' 1
implicit conversion from 'number' to 'string' EA CONTROLLER TEST.mq5 39 42
implicit conversion from 'number' to 'string' EA CONTROLLER TEST.mq5 111 42
code generated 1
0 errors, 2 warnings, 569 msec elapsed, cpu='X64 Regular' 3
if (ticket > 0 && PositionSelect(ticket))
PositionSelect(X) --- the X is supposed to be the symbol. search this site for how to use PositionSelect
Maybe you meant to use PositionSelectByTicket(ticket) ????- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear MQL5 Community,
I am seeking guidance on resolving a persistent issue I am facing while developing an EA on the MT5 platform. Despite several iterations and revisions, the problem remains unresolved, and I would greatly appreciate your insights.
My Requirements:
EA Purpose:
The EA monitors active trades for orders meeting or exceeding a user-defined lot size ( TriggerLotSize ).
If such a trade is detected:
The EA determines whether it’s a buy or sell order.
It opens a new chart and applies a specific template:
For buy orders: BUY_Transmitter_template.tpl
For sell orders: SELL_Transmitter_template.tpl
The EA tracks the trade's progress, and when its Take Profit (TP) is hit:
It closes the EA running on the corresponding chart without affecting any other charts or EAs.
The Issue:
I am encountering persistent warnings related to "implicit conversion from 'number' to 'string'" during compilation, particularly in debug or logging operations using Print() and StringFormat() .
Here is an example of where the warning occurs:
LogDebug(StringFormat("Trigger Order Found: Ticket = %llu | MagicNumber = %d | Type = %s | LotSize = %.2f", TrackedTicket, TrackedMagicNumber, orderType == POSITION_TYPE_BUY ? "Buy" : "Sell", lotSize));
The warning frequently appears whenever variables such as TrackedTicket (of type ulong ) or TrackedMagicNumber (of type int ) are used in concatenations or formatting.
Additional Details:
My EA logic also involves the use of ChartOpen() and ChartClose() functions to manage charts dynamically. However, I want to ensure that no unrelated charts are affected during closure.
What I Have Tried:
Replacing concatenations using + with the StringFormat() function to handle all string formatting explicitly. While it improved readability, the warnings persisted.
Explicit typecasting (e.g., using (long) or IntegerToString() ) to resolve the conversion warnings.
Avoiding concatenation entirely in Print() statements by passing arguments directly, separated by commas:
Print("Position Index:", i, "| Ticket:", (long)ticket);
Using debug messages to isolate the problem and ensure proper variable values are logged during execution.
Request for Assistance:
I kindly request the following:
Advice on how to permanently resolve the implicit conversion warnings while maintaining robust and clear debug logging.
Suggestions for improving the EA logic to ensure charts are dynamically managed without interfering with other EA instances running on different charts.
=========================================================================
Error Message:
'EA CONTROLLER TEST.mq5' 1
implicit conversion from 'number' to 'string' EA CONTROLLER TEST.mq5 38 42
implicit conversion from 'number' to 'string' EA CONTROLLER TEST.mq5 94 42
code generated 1
0 errors, 2 warnings, 485 msec elapsed, cpu='X64 Regular' 3
Here is the code for reference: