Using MarketInto()

 

Hello everybody,

I'm having problems with the MarketInfo command.

The following little test program deliveres a correct result when attached to the EURUSD chart.

However it doesn't deliver any result when attached to a chart different than EURUSD.

Does anybody have an idea why MarketInfo command behaves like that?

//+------------------------------------------------------------------+
//| TestProgram.mq4 |
//| JZ |
//| |
//+------------------------------------------------------------------+
#property copyright "JZ"
#property link ""

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
// Get ask price
//
double Pip_val_counter_ask = 0;
string Pip_val_counter_curr = "EURUSD";
Pip_val_counter_ask = MarketInfo(Pip_val_counter_curr,10);

Print("Pip_val_counter_curr ",Pip_val_counter_curr, " Pip_val_counter_ask ",Pip_val_counter_ask);

//----
return(0);
}
//+------------------------------------------------------------------+
 

You've already defined the currency as EURUSD. Replace with Symbol() to get the currency of the attached chart.

int start()
{
//----
// Get ask price
//
double Pip_val_counter_ask = MarketInfo(Symbol(),10);

Print("Pip_val_counter_curr ",Symbol(), " Pip_val_counter_ask ",Pip_val_counter_ask);

//----
return(0);
}
 
Clearpaper:

You've already defined the currency as EURUSD. Replace with Symbol() to get the currency of the attached chart.



Hello Clearpaper,

Thanks for your comment.

The purpose of this little test program is to demonstrate its funcionality. I'm aware of the Symbol() command.

I'm currently writing a Risk management application and as part of it, the Pip value in my accounting currency.

As a excemple:

Accounting in: USD

Trading Chart: EURGBP

Cross currency pair: GBPUSD (pair used for cross rate calculation)


So, trading the EUR/GBP pair, I want to access the ask price in the Market Watch file using the MarketInfo("GBPUSD",10) command.

And that's when MarketInfo does not perform as expected. I receive no information for the pair GBPUSD.


The question is why ?

Is MarketInfo designe to deliver information ONLY for the chart you have the Expert advisor attached to?


If you have an idea, this would be great. Thank again.

 

  1. Pip_val_counter_ask = MarketInfo(Pip_val_counter_curr,10);
    Don't use numbers, use the enumerations provided
    Pip_val_counter_ask = MarketInfo(Pip_val_counter_curr,MODE_ASK);

  2. Are you using the tester? You can not get bar zero data from other currencies in the tester.
 
WHRoeder:

  1. Don't use numbers, use the enumerations provided
  2. Are you using the tester? You can not get bar zero data from other currencies in the tester.

Hello WHRoeder,

Thanks for your comments. Yes, I noticed the double posting and it won't happen again.

I used MODE_ASK as well, with the same negative result.

I use the Strategy Tester. Do you suggest this has something to do with the Tester ?

Are you saying that when testing my EA in the EURGBP chart of the tester, I have NO access to the currency pair USDGBP?

The MarketInfo(Symbol(), MODE_ASK) delivers the Ask price for the current chart. That's fine and works well.

I'm writing a risk management tool, calculating the Cross Rate Pip Value in my account currency (USD).

In order to do that I need the ask price of 2 different currency pairs.

For example:

Trading EURGBP, I need the ask price for EURGBP and USDGBP.

Where I run into problems is with the MarketInfo("USDGBP",MODE_ASK). It doesn't deliver any results.

As far as I know, with the MarketInfo command, I should be able to access any currency pair present in the Market Watch window.

Thanks again for your help.








 

I see what you mean. Might have to do with the Print command printing only strings properly. Try this:

int start()
{
//----
// Get ask price
//
string Pip_val_counter_ask = DoubleToStr(MarketInfo(Symbol(),10),5);

Print("Pip_val_counter_curr ",Symbol(), " Pip_val_counter_ask ",Pip_val_counter_ask);

//----
return(0);
}

Edit: Saw your post just above, it's GBPUSD, not USDGBP, might be another reason for getting a null value.

And going by what you're trying to achieve, MODE_TICKVALUE would get you there much faster.

 
Clearpaper:

I see what you mean. Might have to do with the Print command printing only strings properly. Try this:

Edit: Saw your post just above, it's GBPUSD, not USDGBP, might be another reason for getting a null value.

And going by what you're trying to achieve, MODE_TICKVALUE would get you there much faster.


Hello guys

It is the tester!!!!!!

WHRoeders tip was correct. The tester can obviousely not handle zero bar information.

My little program works perfect in a live environment.

So, many thanks to my helpers.

 
JuergZimmermann:
WHRoeders tip was correct. The tester can obviousely not handle zero bar information.

The limits of the tester is well documented.

You can not get bar zero data for other TF/pairs, that includes Bid/Ask.

 
Clearpaper:

I see what you mean. Might have to do with the Print command printing only strings properly. Try this:

Print/Alert/Comment all convert numbers to string. Only they convert to just 4 digits, even on a 5 digit broker. Use DoubleToStr(d, Digits) to see all the digits.
// string Pip_val_counter_ask = DoubleToStr(MarketInfo(Symbol(),10),5);
   string Pip_val_counter_ask = DoubleToStr(MarketInfo(Symbol(),MODE_ASK),Digits);
Don't put plain numbers in the code, use the proper constants.
 

Thanls Gentlemen, for the tips and tricks.

It saved me a lot of hassle....

Have a nice week.