SymbolInfo
Download scriptThis script is designed to automate the collection and export of essential market data for specific trading pairs into a structured report format. Instead of requiring a user to manually look up various figures across different windows, the tool gathers this information instantly and saves it to a dedicated file.
Core Functionality
1. Automated Data Collection The script targets a pre-defined list of major currency pairs (such as EURUSD, GBPUSD, etc.) and extracts several key pieces of technical information for each:
- Swap Rates: The costs associated with holding positions overnight (Long and Short).
- Spread: The difference between the buy and sell prices.
- Stop Levels: The minimum distance allowed for placing stop orders.
- Lot Sizes: The standard contract sizes for those symbols.
2. Intelligent Balance Calculation One of the more sophisticated features of this logic is its ability to calculate a "Balance" value based on the currency prefix of the trading pair. The script identifies if a pair starts with AUD, EUR, GBP, NZD, or USD and applies a specific mathematical formula tailored to that currency. This ensures that the final data reflects a normalized value appropriate for each specific asset type.
3. File Generation and Formatting Rather than just displaying information on the screen, the script creates a permanent record:
- Report Creation: It generates a CSV file (by default named "SymbolInfo.csv").
- Header Information: The file is initialized with a timestamp of the current local date and the name of the trading company.
- Structured Layout: It builds a clean table layout with headers, making the resulting file easy to read in spreadsheet software like Excel.
- Customizable Separators: Users have the option to define how the data is separated (e.g., using dots or other characters) to ensure compatibility with different regional settings.
4. User Feedback Once the process is complete, the script provides immediate confirmation by displaying a notification on the main trading chart and in the system log, letting the user know exactly which file was generated.
//+------------------------------------------------------------------+
//| SymbolInfo.mq4 |
//| Êèì Èãîðü Â. aka KimIV |
//| http://www.kimiv.ru |
//| 02.04.2006 Ñêðèïò äëÿ âûãðóçêè èíôîðìàöèè î ñèìâîëàõ. |
//| 04.05.2006 Äîáàâèë ñòîëáåö "Çàëîã". |
//+------------------------------------------------------------------+
#property copyright "Êèì Èãîðü Â. aka KimIV"
#property link "http://www.kimiv.ru"
#property show_inputs
//------- Âíåøíèå ïàðàìåòðû ñêðèïòà ---------------------------------+
extern string siFileName = "SymbolInfo.csv";
extern string siSeparator = ".";
//------- Ãëîáàëüíûå ïåðåìåííûå ñêðèïòà -----------------------------+
string siMS[16]={"AUDUSD","CHFJPY","EURAUD","EURCAD","EURCHF",
"EURGBP","EURJPY","EURUSD","GBPCHF","GBPJPY",
"GBPUSD","GOLD","NZDUSD","USDCAD","USDCHF","USDJPY"};
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
void start()
{
double b, ls, z;
double aud = MarketInfo("AUDUSD", MODE_BID);
double eur = MarketInfo("EURUSD", MODE_BID);
double gbp = MarketInfo("GBPUSD", MODE_BID);
double nzd = MarketInfo("NZDUSD", MODE_BID);
int d, i, k;
string st;
FileDelete(siFileName);
st = ";" + TimeToStr(LocalTime(), TIME_DATE) + ";" + AccountCompany();
WritingLineInFile(siFileName, st);
WritingLineInFile(siFileName, "");
st = "¹;Ñèìâîë;Long;Short;Ñïðýä;Ñòîïû;Êîíòðàêò;Çàëîã";
WritingLineInFile(siFileName, st);
for(i = 0; i < ArraySize(siMS); i++)
{
b = MarketInfo(siMS[i], MODE_BID);
d = MarketInfo(siMS[i], MODE_DIGITS);
ls = MarketInfo(siMS[i], MODE_LOTSIZE);
z = 0;
st = DoubleToStr(i + 1, 0) + ";" +
siMS[i] + ";" +
DoubleToStr(MarketInfo(siMS[i], MODE_SWAPLONG), 2) + ";" +
DoubleToStr(MarketInfo(siMS[i], MODE_SWAPSHORT), 2) + ";" +
DoubleToStr(MarketInfo(siMS[i], MODE_SPREAD), 0) + ";" +
DoubleToStr(MarketInfo(siMS[i], MODE_STOPLEVEL), 0) + ";" +
DoubleToStr(ls, 0) + ";";
if(d == 2)
k = 10000;
else
k = 100;
if(StringSubstr(siMS[i], 0, 3) == "AUD")
z = ls*aud / 100;
if(StringSubstr(siMS[i], 0, 3) == "EUR")
z = ls*eur / 100;
if(StringSubstr(siMS[i], 0, 3) == "GBP")
z = ls*gbp / 100;
if(StringSubstr(siMS[i], 0, 3) == "NZD")
z = ls*nzd / 100;
if(StringSubstr(siMS[i], 0, 3) == "USD")
z = ls / 100; // else z = ls*b / k;
st = st + DoubleToStr(z, 2);
if(siSeparator != ".")
st = StrTran(st, ".", siSeparator);
WritingLineInFile(siFileName, st);
}
st = "Ñôîðìèðîâàí ôàéë: " + siFileName;
Comment(st);
Print(st);
}
//+------------------------------------------------------------------+
//| Çàìåíà ïîäñòðîêè |
//| Ïàðàìåòðû: |
//| str - òåêñòîâàÿ ñòðîêà, â êîòîðîé ïðîèçâîäèòñÿ çàìåíà |
//| strfrom - çàìåíÿåìàÿ ïîäñòðîêà |
//| strto - çàìåíÿþùàÿ ïîäñòðîêà |
//+------------------------------------------------------------------+
string StrTran(string str, string strfrom, string strto)
{
int n;
string outstr = "", tempstr;
for(n = 0; n < StringLen(str); n++)
{
tempstr = StringSubstr(str, n, StringLen(strfrom));
if(tempstr == strfrom)
{
outstr = outstr + strto;
n = n + StringLen(strfrom) - 1;
}
else
outstr = outstr + StringSubstr(str, n, 1);
}
return(outstr);
}
//+------------------------------------------------------------------+
//| Çàïèñü ñòðîêè â ôàéë |
//+------------------------------------------------------------------+
void WritingLineInFile(string FileName, string text)
{
int file_handle = FileOpen(FileName, FILE_READ|FILE_WRITE, " ");
if(file_handle > 0)
{
FileSeek(file_handle, 0, SEEK_END);
FileWrite(file_handle, text);
FileClose(file_handle);
}
}
//+------------------------------------------------------------------+
Comments