PDA

View Full Version : Anything wrong with this: Symbol in Market Watch



Ancrealv
12-12-2012, 09:48 AM
Hello,

I have searched a bit how to check if a Symbol is in the Market View window.

Most of the code follow something along this approach:

Inserted Code hFile = FileOpenHistory(symbols.sel, FILE_BIN|FILE_READ); if(hFile lt; 0) return(-1); SymbolsTotal = (FileSize(hFile) - 4) / 128; FileSeek(hFile, 4, SEEK_SET); for(int I = 0; I lt; SymbolsTotal; I ) if(FileReadString(hFile, 12) == SymbolName) FileClose(hFile); //corrected return(true); //OK FileSeek(hFile, 116, SEEK_CUR); FileClose(hFile); return(false); //Not found Anything wrong with this: easy check the error code: seems simpler and probably quicker
Inserted Code #include lt;stderror.mqhgt; GetLastError(); //clean last err int iL.Digits = MarketInfo(Symbol, MODE_DIGITS); if (GetLastError() == ERR_UNKNOWN_SYMBOL) //Not found return(false); else //OK return(true); } Thanks for any information

R

Mummai
10-31-2021, 08:20 PM
hello,

I've searched a little how to assess if a Symbol is in the Market Watch window.

The majority of the code follow something along this approach:

Inserted Code hFile = FileOpenHistory(symbols.sel, FILE_BIN|FILE_READ); if(hFile lt; 0) return(-1); SymbolsTotal = (FileSize(hFile) - 4) / 128; FileSeek(hFile, 4, SEEK_SET); for(int I = 0; I lt; SymbolsTotal; I ) if(FileReadString(hFile, 12) == SymbolName) return(true); //OK FileSeek(hFile, 116, SEEK_CUR); FileClose(hFile); return(false); //Not found [b]Anything wrong with... looks good on paper, however I think the first code example is meant to be a jumping-off tip for further reading of information in the file and isn't meant to only see if a symbol exists or not. Else it is missing a fileclose before coming accurate.

Ancrealv
10-31-2021, 09:41 PM
else it is missing a fileclose before returning true. My poor: THANKS. Corrected it in the article. Was speaking to this code snipped of: http://forum.mql4.com/24948 ChartWindow
and wondered whether it would be not simpler only checking the error code. .

But I am not sure if the other egy: looping throughout the symbols.sel file has some benefits like I mostly saw this egy on the net

Mummai
10-31-2021, 11:02 PM
My bad: THANKS. Adjusted it. Was speaking to the code snipped of: http://forum.mql4.com/24948 ChartWindow
and wondered whether it would be not easier just checking the error code. .

But I am not sure whether another egy: looping throughout the symbols.sel document has some advantages as I mostly watched this approach on the net did you come to some conclusion. I am still curious about this as far as I could tell the file scanning variant was likely just the first idea of how to go about doing it.