mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-16 05:48:05 +00:00
refactor: into a class-based structure
This commit is contained in:
@@ -1,96 +1,143 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| SymbolInfoStringChecker.mq5 |
|
//| SymbolInfoStringChecker.mq5 |
|
||||||
//| Copyright 2025, MetaQuotes Ltd. |
|
//| Copyright 2025, xxxxxxxx |
|
||||||
//| https://www.mql5.com |
|
//| |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, MetaQuotes Ltd."
|
#property copyright "Copyright 2025, xxxxxxxx"
|
||||||
#property link "https://www.mql5.com"
|
#property link ""
|
||||||
#property version "1.01"
|
#property version "2.00" // Refactored into a class-based structure
|
||||||
#property description "Checks and displays all STRING properties for the current symbol."
|
#property description "Checks and displays all STRING properties for the current symbol."
|
||||||
|
|
||||||
#include <Trade\SymbolInfo.mqh>
|
#include <Trade\SymbolInfo.mqh>
|
||||||
|
|
||||||
//--- Array of all string properties to check.
|
//+------------------------------------------------------------------+
|
||||||
const ENUM_SYMBOL_INFO_STRING G_STRING_PROPERTIES[] =
|
//| Class to check and display STRING symbol properties |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
class CSymbolStringPropertyChecker
|
||||||
{
|
{
|
||||||
SYMBOL_BASIS,
|
private:
|
||||||
SYMBOL_CATEGORY,
|
CSymbolInfo m_symbol_info;
|
||||||
SYMBOL_COUNTRY,
|
string m_symbol_name;
|
||||||
SYMBOL_SECTOR_NAME,
|
|
||||||
SYMBOL_INDUSTRY_NAME,
|
//--- Array of all string properties to check.
|
||||||
SYMBOL_CURRENCY_BASE,
|
static const ENUM_SYMBOL_INFO_STRING S_STRING_PROPERTIES[];
|
||||||
SYMBOL_CURRENCY_PROFIT,
|
|
||||||
SYMBOL_CURRENCY_MARGIN,
|
public:
|
||||||
SYMBOL_BANK,
|
CSymbolStringPropertyChecker(const string symbol);
|
||||||
SYMBOL_DESCRIPTION,
|
bool Run(void);
|
||||||
SYMBOL_EXCHANGE,
|
|
||||||
SYMBOL_FORMULA,
|
private:
|
||||||
SYMBOL_ISIN,
|
void PrintHeader(void);
|
||||||
SYMBOL_PAGE,
|
void PrintFooter(void);
|
||||||
SYMBOL_PATH
|
void PrintProperty(ENUM_SYMBOL_INFO_STRING property_id);
|
||||||
|
string FormatValue(string value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//--- Static member initialization
|
||||||
|
const ENUM_SYMBOL_INFO_STRING CSymbolStringPropertyChecker::S_STRING_PROPERTIES[] =
|
||||||
|
{
|
||||||
|
SYMBOL_BASIS, SYMBOL_CATEGORY, SYMBOL_COUNTRY, SYMBOL_SECTOR_NAME,
|
||||||
|
SYMBOL_INDUSTRY_NAME, SYMBOL_CURRENCY_BASE, SYMBOL_CURRENCY_PROFIT,
|
||||||
|
SYMBOL_CURRENCY_MARGIN, SYMBOL_BANK, SYMBOL_DESCRIPTION,
|
||||||
|
SYMBOL_EXCHANGE, SYMBOL_FORMULA, SYMBOL_ISIN, SYMBOL_PAGE, SYMBOL_PATH
|
||||||
|
};
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Constructor |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
CSymbolStringPropertyChecker::CSymbolStringPropertyChecker(const string symbol) : m_symbol_name(symbol)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Runs the property check process |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
bool CSymbolStringPropertyChecker::Run(void)
|
||||||
|
{
|
||||||
|
if(!m_symbol_info.Name(m_symbol_name))
|
||||||
|
{
|
||||||
|
PrintFormat("Error: Symbol '%s' not found or not available in Market Watch.", m_symbol_name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_symbol_info.Refresh();
|
||||||
|
|
||||||
|
PrintHeader();
|
||||||
|
|
||||||
|
for(int i = 0; i < ArraySize(S_STRING_PROPERTIES); i++)
|
||||||
|
{
|
||||||
|
PrintProperty(S_STRING_PROPERTIES[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintFooter();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Prints a single property's status and value |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
void CSymbolStringPropertyChecker::PrintProperty(ENUM_SYMBOL_INFO_STRING property_id)
|
||||||
|
{
|
||||||
|
string value;
|
||||||
|
string result_str;
|
||||||
|
string property_name = EnumToString(property_id);
|
||||||
|
|
||||||
|
ResetLastError();
|
||||||
|
if(m_symbol_info.InfoString(property_id, value))
|
||||||
|
{
|
||||||
|
result_str = StringFormat("%-35s | Status: SUPPORTED | Value: %s",
|
||||||
|
property_name,
|
||||||
|
FormatValue(value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result_str = StringFormat("%-35s | Status: FAILED | Error: %d",
|
||||||
|
property_name,
|
||||||
|
GetLastError());
|
||||||
|
}
|
||||||
|
Print(result_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Formats a STRING property value into a readable string |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
string CSymbolStringPropertyChecker::FormatValue(string value)
|
||||||
|
{
|
||||||
|
if(value == "")
|
||||||
|
{
|
||||||
|
return("<EMPTY>");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return("'" + value + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Prints the header for the output |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
void CSymbolStringPropertyChecker::PrintHeader(void)
|
||||||
|
{
|
||||||
|
Print("--- Symbol String Property Checker Started ---");
|
||||||
|
PrintFormat("Checking symbol: %s", m_symbol_name);
|
||||||
|
Print("------------------------------------------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Prints the footer for the output |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
void CSymbolStringPropertyChecker::PrintFooter(void)
|
||||||
|
{
|
||||||
|
Print("------------------------------------------------------------------");
|
||||||
|
Print("--- Check Completed ---");
|
||||||
|
}
|
||||||
|
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//| Script program start function |
|
//| Script program start function |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
void OnStart()
|
void OnStart()
|
||||||
{
|
{
|
||||||
string symbol = _Symbol;
|
CSymbolStringPropertyChecker checker(_Symbol);
|
||||||
CSymbolInfo m_symbol_info;
|
checker.Run();
|
||||||
|
|
||||||
if(!m_symbol_info.Name(symbol))
|
|
||||||
{
|
|
||||||
PrintFormat("Error: Failed to set symbol '%s'.", symbol);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_symbol_info.Refresh();
|
|
||||||
|
|
||||||
Print("--- Symbol Property Checker Started ---");
|
|
||||||
PrintFormat("Checking symbol: %s", symbol);
|
|
||||||
Print("------------------------------------------------------------------");
|
|
||||||
|
|
||||||
string value;
|
|
||||||
string result_str;
|
|
||||||
|
|
||||||
for(int i = 0; i < ArraySize(G_STRING_PROPERTIES); i++)
|
|
||||||
{
|
|
||||||
ResetLastError();
|
|
||||||
bool success = m_symbol_info.InfoString(G_STRING_PROPERTIES[i], value);
|
|
||||||
int error = GetLastError();
|
|
||||||
|
|
||||||
// Use StringFormat with padding for consistent alignment
|
|
||||||
string property_name = EnumToString(G_STRING_PROPERTIES[i]);
|
|
||||||
string property_name_padded = StringFormat("%-35s", property_name);
|
|
||||||
|
|
||||||
if(success)
|
|
||||||
{
|
|
||||||
string display_value;
|
|
||||||
if(value == "")
|
|
||||||
{
|
|
||||||
// Indicate that the property is supported but the value is empty
|
|
||||||
display_value = "<EMPTY>";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Enclose the value in single quotes for clarity
|
|
||||||
display_value = "'" + value + "'";
|
|
||||||
}
|
|
||||||
|
|
||||||
result_str = StringFormat("%s | Status: SUPPORTED | Value: %s",
|
|
||||||
property_name_padded,
|
|
||||||
display_value);
|
|
||||||
Print(result_str);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result_str = StringFormat("%s | Status: FAILED | Error: %d",
|
|
||||||
property_name_padded,
|
|
||||||
error);
|
|
||||||
Print(result_str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Print("------------------------------------------------------------------");
|
|
||||||
Print("--- Check Completed ---");
|
|
||||||
}
|
}
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
|
|||||||
Reference in New Issue
Block a user