Symbol name for MarketInfo function must be a string

To add comments, please log in or register
Jan Klimo
116
Jan Klimo  

Hey guys,

I've been looking at this strage issue for a couple of hours now and still can't find a solution, so I am asking you for ideas.


I am loading a list of symbols from one long string using StringSubstr into a string array. Then I use this for all the symbols:

    if ((MarketInfo(symbol[j], MODE_POINT) == 0)) continue;
    real_spread = (MarketInfo(symbol[j], MODE_ASK) - MarketInfo(symbol[j], MODE_BID))/MarketInfo(symbol[j], MODE_POINT);


which are the only lines where MarketInfo is used. All the arrays get populated, calculations done, but I still get this error:

2009.02.02 14:06:58 ... EURGBP,Weekly: symbol name for MarketInfo function must be a string


Now tell me, how come when symbol[j] is an item of a string array, can it be something else than a string??


Any help appreciated.


Jan

Alexander
1509
Alexander  
janklimo:

Now tell me, how come when symbol[j] is an item of a string array, can it be something else than a string??

Try to check symbol[j] value. I cant see other possible problems

Justin Abene
203
Justin Abene  
try Comment(symbol[j]); to see what it's saying, or Print();
blogzr3
505
blogzr3  

If symbol[j] is uninitialised, you will get that error.


Of course, the error message could have been more helpful, but MQL4 does have its quirks...:)

fbj
1049
fbj  
int start()
{
  string symbol[]={"GBPUSD","gbpusd","123456","eUrchF","EURCHF","USDJPY"};
  int lastSymIndex=ArraySize(symbol);
  for(int j=0;j<lastSymIndex;j++)
    Print("MarketInfo(",symbol[j],",MODE_POINT)","=",DoubleToStr(MarketInfo(symbol[j],MODE_POINT),8)
          ,", Error=",ErrorDescription(GetLastError()));
  return(0);
}

above is quicky and maybe see that nothing done produced your error - so... how did you get it?

is helpful to see actual copied lines from Terminal > Experts tab.

anyway, below is test results for above code and maybe of interest - maybe not ;)

.

2009.02.03 10:14:27 _quicky GBPUSD,M15: MarketInfo(USDJPY,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 10:14:27 _quicky GBPUSD,M15: MarketInfo(EURCHF,MODE_POINT)=0.00001000, Error=no error
2009.02.03 10:14:27 _quicky GBPUSD,M15: MarketInfo(eUrchF,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 10:14:27 _quicky GBPUSD,M15: MarketInfo(123456,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 10:14:27 _quicky GBPUSD,M15: MarketInfo(gbpusd,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 10:14:27 _quicky GBPUSD,M15: MarketInfo(GBPUSD,MODE_POINT)=0.00001000, Error=no error
.

NOTE:USDJPY is valid symbol but is not present in MarketWatch therefore Terminal not 'know' it's data... iow, result=0 can often means MarketWatch needs looking at.

Justin Abene
203
Justin Abene  
Are you sure your broker allows trading with USDJPY?
fbj
1049
fbj  

"Are you sure your broker allows trading with USDJPY?"

it has been discussed on forum about need to have the symbol in MarketWatch else Terminal not supply info - many including me, have been mistaken and thrown our toys about shouting that Terminal is having problems... but not so, is our issue. The docs are hard to read and sometimes interpret meaning author meant. imho, People spend too much time talking about some things, far better to write test harness code and prove to self the truth or falsity of what docs say. Is far faster and is also helping to learn more ;)

.

below see same code as shown prev post. Ran two times. first time MarketWatch not have USDJPY, second time it does.

2009.02.03 18:24:55 _quicky GBPUSD,M15: removed
2009.02.03 18:24:55 stdlib GBPUSD,M15: removed
2009.02.03 18:24:55 stdlib GBPUSD,M15: uninit reason 0
2009.02.03 18:24:55 _quicky GBPUSD,M15: uninit reason 0
2009.02.03 18:24:55 _quicky GBPUSD,M15: MarketInfo(USDJPY,MODE_POINT)=0.00100000, Error=no error
2009.02.03 18:24:55 _quicky GBPUSD,M15: MarketInfo(EURCHF,MODE_POINT)=0.00001000, Error=no error
2009.02.03 18:24:55 _quicky GBPUSD,M15: MarketInfo(eUrchF,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 18:24:55 _quicky GBPUSD,M15: MarketInfo(123456,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 18:24:55 _quicky GBPUSD,M15: MarketInfo(gbpusd,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 18:24:55 _quicky GBPUSD,M15: MarketInfo(GBPUSD,MODE_POINT)=0.00001000, Error=no error
2009.02.03 18:24:55 stdlib GBPUSD,M15: loaded successfully
2009.02.03 18:24:55 _quicky GBPUSD,M15: loaded successfully
second time code run


MarketWatch WITH udsjpy

.

.

.

2009.02.03 18:23:42 _quicky GBPUSD,M15: removed
2009.02.03 18:23:42 stdlib GBPUSD,M15: removed
2009.02.03 18:23:42 stdlib GBPUSD,M15: uninit reason 0
2009.02.03 18:23:42 _quicky GBPUSD,M15: uninit reason 0
2009.02.03 18:23:42 _quicky GBPUSD,M15: MarketInfo(USDJPY,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 18:23:42 _quicky GBPUSD,M15: MarketInfo(EURCHF,MODE_POINT)=0.00001000, Error=no error
2009.02.03 18:23:42 _quicky GBPUSD,M15: MarketInfo(eUrchF,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 18:23:42 _quicky GBPUSD,M15: MarketInfo(123456,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 18:23:42 _quicky GBPUSD,M15: MarketInfo(gbpusd,MODE_POINT)=0.00000000, Error=unknown symbol
2009.02.03 18:23:42 _quicky GBPUSD,M15: MarketInfo(GBPUSD,MODE_POINT)=0.00001000, Error=no error
2009.02.03 18:23:42 stdlib GBPUSD,M15: loaded successfully
2009.02.03 18:23:42 _quicky GBPUSD,M15: loaded successfully
first time code run


MarketWatch NO usdjpy

.

Jan Klimo
116
Jan Klimo  

Hi guys,

thanks so much for your ideas. I managed to solve the problem and want to share it in case somebody encounters it in the future. I don't know why but the array was really badly initialized, so this helped:


    for (int a = 0; a <= 150; a++)
    {
      spread[a] = 0;
      limits[a] = 0;
      symbol[a] = "";
    }


before populating the array with my data.


Cheers,

Jan

fbj
1049
fbj  

interesting but why would your code be using string array elements that had gash in them anyway?

if you say had 10 sym strings in 0..9 which you either loaded via []={"xxx",...}; compile time initialisation OR via some sort of runtime loading of elements

then where is the issue?

surely is a question of array indexing, eg: if <0||>9 then what else would you expect?

iow, code should 'know' the what data stored and how much stored related to []'s

:]

just an observation - as this is what immediately hit me when read your comment.

anyway - what works for each is what counts in the end!

thanks for the heads up reply.

Jan Klimo
116
Jan Klimo  
Well, it should have been obvious but it wasn't. I don't know whether it is just my impression, but when you use external functions from a windows dll (I use wininet.dll), the compiler sometimes compiles an erroneous binary with unexpected behaviour.
fbj
1049
fbj  

Oh... you got me there, I've used simple .dll stuff only. Your comments on this are duly noted and should the need arise and I employ more heavy api's I'll surely take care!

Thank you.

.

maybe [for me anyway] the lesson here is to always code for the unexpected. I do try very hard to make code bullet proof and also to not make assumptions. Can get hard and [of course;] "to err is human..." - hahaaa, that's my excuse anyways :O)

To add comments, please log in or register