MarketInfo return 0

 

hi,

I use MT4 demo account.

double bid =MarketInfo("EURUSD",MODE_BID);

Print("bid number is ", DoubleToStr(bid, 4));

but just return 0

I can only get

double Price = Bid;
Print(Bid);

This is ok.

The reason I use MarketInfo is that when my EA is attatched to a chart, I want to read tick data from other pairs at the same time. So I don't use Symbol().

Historical Testing not working is ok with me. I just want to do Live trading based on real-time tick data from other pairs.

Could anyone help?

Thanks a lot.

 

Try . . .

RefreshRates();

double bid =MarketInfo("EURUSD",MODE_BID);

Print("bid number is ", DoubleToStr(bid, 4));
 
RaptorUK:

Try . . .


Thank you for response.

In fact, I had already added

RefreshRates();

in the beginning.

but it still returns 0.

 

pcchu:

...

Print("bid number is ", DoubleToStr(bid, 4));

but just return 0

...

Look at Market Watch window - right click in it > Symbols > you must have the required syms Shown else Terminal does not have server quotes...

eg, I used: double bid =MarketInfo("AUDCAD",MODE_BID); when AUDCAD not Shown in Market Watch > result was 0

Second time around with AUDCAD Shown > result was a valid Bid value.

NOTE:type double defaults to 4 digits in Print() and Comment(); DoubleToStr(abc,Digits) useful if subPip broker as need that 3rd/5th digit when printing; Also especially with market order actuals via NormalizeDouble(abc,Digits)

pcchu:

...

The reason I use MarketInfo is that when my EA is attatched to a chart, I want to read tick data from other pairs at the same time. So I don't use Symbol().

Historical Testing not working is ok with me. I just want to do Live trading based on real-time tick data from other pairs.

...

Please be aware that multiSym trading from one EA is problematical.

What happens when start() not reentered due to slowness of new incoming ticks on the default chart?

What happens to your fast moving off chart symbol during that time?

"Real-time" will not be, due to above...

Consider while(1)... in start() should you still be keen. However that just opens another can of worms.

 
fbj:

Look at Market Watch window - right click in it > Symbols > you must have the required syms Shown else Terminal does not have server quotes...

eg, I used: double bid =MarketInfo("AUDCAD",MODE_BID); when AUDCAD not Shown in Market Watch > result was 0

Second time around with AUDCAD Shown > result was a valid Bid value.

NOTE:type double defaults to 4 digits in Print() and Comment(); DoubleToStr(abc,Digits) useful if subPip broker as need that 3rd/5th digit when printing; Also especially with market order actuals via NormalizeDouble(abc,Digits)

Please be aware that multiSym trading from one EA is problematical.

What happens when start() not reentered due to slowness of new incoming ticks on the default chart?

What happens to your fast moving off chart symbol during that time?

"Real-time" will not be, due to above...

Consider while(1)... in start() should you still be keen. However that just opens another can of worms.


Thank you for response.

"EURUSD" is in Market Watch window, but

double bid =MarketInfo("EURUSD",MODE_BID);

Print("bid number is ", DoubleToStr(bid, 4));

still get 0

 

What test code using? Can you show? I cannot understand your result. Seriously... I did 1 line script: Print(MarketInfo("AUDCAD",MODE_BID); Ran twice as originally explained.

Beyond that I have no further input since (for me anyway) I proved to self that with AUDCAD 'hidden' in MarketWatch the result was zero; 'shown' it was non-zero. So I cannot offer any other help excepting request for visual of your complete and exact test code.

Good luck and maybe someone else has answer?

btw. just repeated 'your' code ( 2011.07.12 15:50) on AUDCAD. The script had only below. Two runs. 1 with sym 'hidden' = 0 o/p; 2nd with sym 'shown' = valid bid.

What else can I say?

2011.07.12 15:06:37 test_bitsOfSyntax GBPUSD,M1: bid number is 0.0000
2011.07.12 15:06:56 test_bitsOfSyntax GBPUSD,M1: bid number is 1.0264

double bid =MarketInfo("AUDCAD",MODE_BID);

Print("bid number is ", DoubleToStr(bid, 4));

 
fbj:

What test code using? Can you show? I cannot understand your result. Seriously... I did 1 line script: Print(MarketInfo("AUDCAD",MODE_BID); Ran twice as originally explained.

Beyond that I have no further input since (for me anyway) I proved to self that with AUDCAD 'hidden' in MarketWatch the result was zero; 'shown' it was non-zero. So I cannot offer any other help excepting request for visual of your complete and exact test code.

Good luck and maybe someone else has answer?

btw. just repeated 'your' code ( 2011.07.12 15:50) on AUDCAD. The script had only below. Two runs. 1 with sym 'hidden' = 0 o/p; 2nd with sym 'shown' = valid bid.

What else can I say?

2011.07.12 15:06:37 test_bitsOfSyntax GBPUSD,M1: bid number is 0.0000
2011.07.12 15:06:56 test_bitsOfSyntax GBPUSD,M1: bid number is 1.0264


Thank you for response.

this is my code.

//+------------------------------------------------------------------+
//| ta.mq4 |
//| Copyright © 2011, MetaQuotes Software Corp. |
//| https://www.metaquotes.net// |
//+------------------------------------------------------------------+

int start()
{
//----

RefreshRates();
double bid =MarketInfo("AUDCAD",MODE_BID);
double ask =MarketInfo("AUDCAD",MODE_ASK);
Print("bid number is ", DoubleToStr(bid, 4));
Print("ask number is ", DoubleToStr(ask, 4));
//----
return(0);
}
//+------------------------------------------------------------------+

"AUDCAD" is in Market Watch

2011.07.12 15:28:04 ta EURUSDFXF,H1: ask number is 0.0000
2011.07.12 15:28:04 ta EURUSDFXF,H1: bid number is 0.0000

they just show 0

Maybe they don't work for demo account.

I try two different computers. the same.

 

It works for me . . . can you run your code on a AUDCAD chart and add the following Print statement after your other two . . (my account is a DEMO account, MBT)

Print("Symbol = ",Symbol());
 
pcchu:


Thank you for response.

this is my code.

//+------------------------------------------------------------------+
//| ta.mq4 |
//| Copyright © 2011, MetaQuotes Software Corp. |
//| https://www.metaquotes.net// |
//+------------------------------------------------------------------+

int start()
{
//----

RefreshRates();
double bid =MarketInfo("AUDCAD",MODE_BID);
double ask =MarketInfo("AUDCAD",MODE_ASK);
Print("bid number is ", DoubleToStr(bid, 4));
Print("ask number is ", DoubleToStr(ask, 4));
//----
return(0);
}
//+------------------------------------------------------------------+

"AUDCAD" is in Market Watch

2011.07.12 15:28:04 ta EURUSDFXF,H1: ask number is 0.0000
2011.07.12 15:28:04 ta EURUSDFXF,H1: bid number is 0.0000

they just show 0

Maybe they don't work for demo account.

I try two different computers. the same.

Your tolerance/patience appreciated - unless others pitch in to 'spot the deliberate mistate' - lol, is really a keep trying until success!

I was using demo myself. never test on live - too easy make a/c draining mistake...

Do all your symbols from Broker server have <symbol> and if so "AUDCAD" maybe not being streamed. Just guesing but could it be "AUDCADFXF" that is needed?

I use Alpari UK and sym names are as shown below - have NO experience with another broker...

snap of my Market Watch window with AUDCAD 'shown'

^^^^^

snap of Symbols window when right click > Symbols above window:

Notice that icon preceeding AUDCAD is yellow/enabled - this state happens when click Show and if Hide it is grey/disabled

...

blimey - am at a true loss - your code is ok.

....

HOW ABOUT? run the script on AUDCAD chart?

Can you 'New Chart' AUDCAD or is it AUDCADFXF ?

Nothing like last gasps of a vacant brain... ;)

 
fbj:


Can you 'New Chart' AUDCAD or is it AUDCADFXF ?

Nothing like last gasps of a vacant brain... ;)

Well spotted . . that is the issue . . I think. Change the code from AUDCAD to AUDCADFXF
 
fbj:

Your tolerance/patience appreciated - unless others pitch in to 'spot the deliberate mistate' - lol, is really a keep trying until success!

I was using demo myself. never test on live - too easy make a/c draining mistake...

Do all your symbols from Broker server have <symbol> and if so "AUDCAD" maybe not being streamed. Just guesing but could it be "AUDCADFXF" that is needed?

I use Alpari UK and sym names are as shown below - have NO experience with another broker...

snap of my Market Watch window with AUDCAD 'shown'

^^^^^

snap of Symbols window when right click > Symbols above window:

Notice that icon preceeding AUDCAD is yellow/enabled - this state happens when click Show and if Hide it is grey/disabled

...

blimey - am at a true loss - your code is ok.

....

HOW ABOUT? run the script on AUDCAD chart?

Can you 'New Chart' AUDCAD or is it AUDCADFXF ?

Nothing like last gasps of a vacant brain... ;)


Yes, you guys are right.

just change to "AUDCADFXF", then everything is fine.

I use Forex. Their symbols all have ~FXF.

I was misled by documents.

Thanks a lot for help!!!

Reason: