How to programmatically get the BID or ASK of some Symbol on the MarketWatch without loading the symbol to the chart?

 

Hi There,


I am testing my EA using Strategy Tester (mq4) and I get 0 when I try get ASK/BID of the Symbol on the Market Watch.


My EA is only getting those values when that Symbol is the one open on chart, but somehow I need to be able to get the values into my currently opened Symbol chart which is different from the one on Market Watch.

e.g I'm testing my EA on a chart EURUSD.DMA but I need the ASK/BID price of GBPUSD.DMA, just the price.


Is it possible to get that value?


My example code below:


int start()

{

   SymbolSelect("EURUSD.DMA", true);

   double bid=MarketInfo("GBPUSD.DMA",MODE_BID);

   Print("bid["+bid+"]");

   return(0);

}

 
double ask_1 = MarketInfo(SymbolName(pos,1),MODE_ASK);
double bid_1 = MarketInfo(SymbolName(pos,1),MODE_BID);

double ask_2 = SymbolInfoDouble(SymbolName(pos,1),SYMBOL_ASK);
double bid_2 = SymbolInfoDouble(SymbolName(pos,1),SYMBOL_BID);

SymbolInfoTick(SymbolName(pos,1),tick)){ask_3=tick.ask;}
SymbolInfoTick(SymbolName(pos,1),tick)){bid_3=tick.bid;}       
     
 
Marco vd Heijden:


This still give me zeros, except for the EURUSD that is on chart being tested. Anything wrong?

int start()

{

   MqlTick tick; 

   double ask_1 = MarketInfo("EURUSD.DMA",MODE_ASK);

   double bid_1 = MarketInfo("GBPUSD.DMA",MODE_BID);

   Print("ask_1["+ask_1+"]");

   Print("bid_1["+bid_1+"]");

   double ask_2 = SymbolInfoDouble("GBPUSD.DMA",SYMBOL_ASK);

   double bid_2 = SymbolInfoDouble("GBPUSD.DMA",SYMBOL_BID);

   double ask_3, bid_3;

   if(SymbolInfoTick("GBPUSD.DMA",tick)){ask_3=tick.ask;Print("ask_3["+ask_3+"]");}

   if(SymbolInfoTick("GBPUSD.DMA",tick)){bid_3=tick.bid;Print("bid_3["+bid_3+"]");}  

   return(0);

}

 
Kaone01:


This still give me zeros, except for the EURUSD that is on chart being tested. Anything wrong?

int start()

{

   MqlTick tick; 

   double ask_1 = MarketInfo("EURUSD.DMA",MODE_ASK);

   double bid_1 = MarketInfo("GBPUSD.DMA",MODE_BID);

   Print("ask_1["+ask_1+"]");

   Print("bid_1["+bid_1+"]");

   double ask_2 = SymbolInfoDouble("GBPUSD.DMA",SYMBOL_ASK);

   double bid_2 = SymbolInfoDouble("GBPUSD.DMA",SYMBOL_BID);

   double ask_3, bid_3;

   if(SymbolInfoTick("GBPUSD.DMA",tick)){ask_3=tick.ask;Print("ask_3["+ask_3+"]");}

   if(SymbolInfoTick("GBPUSD.DMA",tick)){bid_3=tick.bid;Print("bid_3["+bid_3+"]");}  

   return(0);

}


Make sure your data is is downloaded in the history center.

 
Kaone01:

This still give me zeros, except for the EURUSD that is on chart being tested. Anything wrong?

Yes your example is giving me zero's too.

But my example is working, so it must be something with your computer.

 

Ok thanks Marco, may you kindly paste in the entire code of your example here, because the example you provided was incomplete, and my attempt to declare undeclared variables for the code to compile from your example has given me zeros, just to be sure? 

 

Can someone please complete this code so that it can compile and give correct values on my Strategy Tester. I just need a value of a symbol not on chart.


Thanks in advance.


double ask_1 = MarketInfo(SymbolName(pos,1),MODE_ASK);
double bid_1 = MarketInfo(SymbolName(pos,1),MODE_BID);

double ask_2 = SymbolInfoDouble(SymbolName(pos,1),SYMBOL_ASK);
double bid_2 = SymbolInfoDouble(SymbolName(pos,1),SYMBOL_BID);

SymbolInfoTick(SymbolName(pos,1),tick)){ask_3=tick.ask;}
SymbolInfoTick(SymbolName(pos,1),tick)){bid_3=tick.bid;}    
 

Ok this had the info I was looking for thanks.


 MqlRates rates[];

Reason: