Why is SymbolName() returning nothing?
Why is SymbolName() returning nothing?
Loading saved threads...
Andy Thompson · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Andy Thompson
Original post: https://stackoverflow.com/questions/64371250
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
In a script designed to loop through every available symbol and log the information available:
int i, j, file_handle;
string InpDirectoryName, InpFileName, Textwrite, mySymbol;
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
int MIIds[29]; // 0-28 market information type IDs
int ST;
MIIds[0] = 1;
MIIds[1] = 2;
MIIds[2] = 5;
for(i=3;i<=28; i++)
MIIds[i] = i+6;
ST = SymbolsTotal(false);
InpDirectoryName = "";
InpFileName = "Test.csv";
Textwrite = "";
file_handle=FileOpen(InpDirectoryName+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV);
if(file_handle!=INVALID_HANDLE)
{
for(i=1;i<=ST; i++)
Print(i);
So far, so good, I get a list of Symbol list positions printed.
However, on attempting to call the corresponding SymbolName(),
mySymbol = SymbolName(i, false);
there is no further print output from the next line:
Print(mySymbol);
The output being as follows:
0 12:29:56.630 Script test EURUSD,H4: loaded successfully
0 12:29:56.667 test EURUSD,H4: initialized
0 12:29:56.669 test EURUSD,H4: 1
...
0 12:29:56.670 test EURUSD,H4: 68
0 12:29:56.670 test EURUSD,H4:
0 12:29:56.670 test EURUSD,H4: uninit reason 0
0 12:29:56.676 Script test EURUSD,H4: removed
As you can see, there are no error codes, just a line of empty output before uninitialisation...
This is the rest of the code for the sake of completeness, although not currently at issue:
SymbolSelect(mySymbol,true);
Textwrite = mySymbol;
for(j=0;i<=28; j++)
Textwrite = Textwrite + "," + MarketInfo(mySymbol,j);
FileWrite(file_handle,Textwrite);
FileClose(file_handle);
}
else Print("Operation FileOpen failed, error ",GetLastError());
}
Any thoughts gratefully received
Quote
Report
Mike · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Mike
Original post: https://stackoverflow.com/a/65434909
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Just a thought, have a look at:
https://docs.mql4.com/files/filereadstring
It looks like you open the file but then you have to use the command
FileReadString
in order to extract the
Symbolname
from the CSV file. Of course, the
Symbolname
has to be in the CSV.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Andy Thompson Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/64371250 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. In a script designed to loop through every available symbol and log the information available: int i, j, file_handle; string InpDirectoryName, InpFileName, Textwrite, mySymbol; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- int MIIds[29]; // 0-28 market information type IDs int ST; MIIds[0] = 1; MIIds[1] = 2; MIIds[2] = 5; for(i=3;i<=28; i++) MIIds[i] = i+6; ST = SymbolsTotal(false); InpDirectoryName = ""; InpFileName = "Test.csv"; Textwrite = ""; file_handle=FileOpen(InpDirectoryName+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV); if(file_handle!=INVALID_HANDLE) { for(i=1;i<=ST; i++) Print(i); So far, so good, I get a list of Symbol list positions printed. However, on attempting to call the corresponding SymbolName(), mySymbol = SymbolName(i, false); there is no further print output from the next line: Print(mySymbol); The output being as follows: 0 12:29:56.630 Script test EURUSD,H4: loaded successfully 0 12:29:56.667 test EURUSD,H4: initialized 0 12:29:56.669 test EURUSD,H4: 1 ... 0 12:29:56.670 test EURUSD,H4: 68 0 12:29:56.670 test EURUSD,H4: 0 12:29:56.670 test EURUSD,H4: uninit reason 0 0 12:29:56.676 Script test EURUSD,H4: removed As you can see, there are no error codes, just a line of empty output before uninitialisation... This is the rest of the code for the sake of completeness, although not currently at issue: SymbolSelect(mySymbol,true); Textwrite = mySymbol; for(j=0;i<=28; j++) Textwrite = Textwrite + "," + MarketInfo(mySymbol,j); FileWrite(file_handle,Textwrite); FileClose(file_handle); } else Print("Operation FileOpen failed, error ",GetLastError()); } Any thoughts gratefully received
Checking account access…