How to import bid/ask from another currency pair? - page 3

 
HosseinKOGO:

What is the problem?

Since your Ask2 and Bid2 are 0, why not add this line after one of them?

Print("MarketInfo Error = ", GetLastError());

And see if there's any useful information?

 
HosseinKOGO:I'm trying GBPAUD as my opened chart and GBPUSD as my second pair.

Did you call download_history for your "second pair," second TF?

 
William Roeder:

Did you call download_history for your "second pair," second TF?

Here is My global area:
extern string SecondPair;
double Ask2,Bid2;

#define HR2400 PERIOD_D1 * 60    // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( int(when % HR2400 ));            }
datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when - TimeOfDay(when) );   }
#define SYMBOL string
#define THIS_SYMBOL ""
bool  download_history(ENUM_TIMEFRAMES period=PERIOD_CURRENT){
   return download_history(_Symbol, period); 
}
bool  download_history(
      SYMBOL            symbol=THIS_SYMBOL,     ///< The symbol required.
      ENUM_TIMEFRAMES   period=PERIOD_CURRENT   /**< The standard timeframe.*/){
   if(symbol == THIS_SYMBOL)     symbol = _Symbol;
   if(period == PERIOD_CURRENT)  period = _Period;
   datetime today = DateOfDay();
   ResetLastError();
   datetime other = iTime(symbol, period, 0);
   if(_LastError == 0 
   && today == DateOfDay(other)) return true;   
   if(_LastError != ERR_HISTORY_WILL_UPDATED
   && _LastError != ERR_NO_HISTORY_DATA
     ) Print(StringFormat("iTime(%s,%i) Failed: %i", symbol, period,_LastError));
   return false;
}
.
.
.

And here is my start function:

   download_history(SecondPair,PERIOD_H4);
   while(!download_history(SecondPair,PERIOD_H4) ){ Sleep(1000); RefreshRates(); }
   Ask2=SymbolInfoDouble(SecondPair,SYMBOL_ASK);
   Bid2=SymbolInfoDouble(SecondPair,SYMBOL_BID);
   Comment(Ask2,Bid2);
.
.
.

in which I put GBPUSD as SecondPair input and do this backtest on GBPAUD chart.

 
Seng Joo Thio:

Since your Ask2 and Bid2 are 0, why not add this line after one of them?

And see if there's any useful information?

I've added this line you mentioned to my start function right after defining Ask2,Bid2 when I've disabled the line below in order to let the candles start and chart goes on
while(!download_history(SecondPair,PERIOD_H4) ){ Sleep(1000); RefreshRates(); }

Error was 4106 which means "Unknown symbol."

Then I disabled the line below as well:

download_history(SecondPair,PERIOD_H4);
And got error 4066 at first (Requested history data in updating state.) Then it turned 4106 for the rest of backtesting.
 
HosseinKOGO:
I've added this line you mentioned to my start function right after defining Ask2,Bid2 when I've disabled the line below in order to let the candles start and chart goes on

Error was 4106 which means "Unknown symbol."

Then I disabled the line below as well:

And got error 4066 at first (Requested history data in updating state.) Then it turned 4106 for the rest of backtesting.

I suspect your symbol name isn't just "GBPUSD"... it might have extra characters somewhere... have u tried this:

Print("Symbol Name = ", Symbol());

before to verify that the symbol name is just six cap letters?

 
Seng Joo Thio:

I suspect your symbol name isn't just "GBPUSD"... it might have extra characters somewhere... have u tried this:

before to verify that the symbol name is just six cap letters?

My symbol() function shows "GBPAUD" since I put it on GBPAUD chart.
Spite that I'm using normal demo account for backtesting, Exactly 6 cap letters. However I've tried this you suggest and got expected result.

I have a warning also when I compile the code: "implicit enum conversion" which is there I've highlighted below. What does that mean exactly?

#define HR2400 PERIOD_D1 * 60    // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( int(when % HR2400 ));            }
datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                          return( when - TimeOfDay(when) );   }
#define SYMBOL string
#define THIS_SYMBOL ""
bool  download_history(ENUM_TIMEFRAMES period=PERIOD_CURRENT){
   return download_history(_Symbol, period); 
}
bool  download_history(
      SYMBOL            symbol=THIS_SYMBOL,     ///< The symbol required.
      ENUM_TIMEFRAMES   period=PERIOD_CURRENT   /**< The standard timeframe.*/){
   if(symbol == THIS_SYMBOL)     symbol = _Symbol;
   if(period == PERIOD_CURRENT)  period = _Period;
   datetime today = DateOfDay();
   ResetLastError();
   datetime other = iTime(symbol, period, 0);
   if(_LastError == 0 
   && today == DateOfDay(other)) return true;   
   if(_LastError != ERR_HISTORY_WILL_UPDATED
   && _LastError != ERR_NO_HISTORY_DATA
     ) Print(StringFormat("iTime(%s,%i) Failed: %i", symbol, period,_LastError));
   return false;
}
 

I think I found the reason why you get zeros... I put these lines in a script and run it on my MT4:

   for (int i=SymbolsTotal(false)-1; i>=0; i--)
   {
      string SName = SymbolName(i,false);
      Ask2=SymbolInfoDouble(SName,SYMBOL_ASK);
      Bid2=SymbolInfoDouble(SName,SYMBOL_BID);
      Print (SName, " Ask = ", Ask2, ", Bid = ", Bid2);
   }

And I realised that Ask2 and Bid2 will be zero for symbols not in my market watch... but once I include them in my market watch, I can get their bid and ask. There is no need to be bothered about history data.

 
Seng Joo Thio:

I think I found the reason why you get zeros... I put these lines in a script and run it on my MT4:

And I realised that Ask2 and Bid2 will be zero for symbols not in my market watch... but once I include them in my market watch, I can get their bid and ask. There is no need to be bothered about history data.

I have those symbols in my market watch window, upper left corner of my MT4.
But if you mean I should include them into my code, How did you include them by code? (If I misunderstood please clarify me since I'm not that pro :D)

 
HosseinKOGO:

I have those symbols in my market watch window, upper left corner of my MT4.
But if you mean I should include them into my code, How did you include them by code? (If I misunderstood please clarify me since I'm not that pro :D)

Not code. 
Since they're already in your market watch window, things are getting more weird. 
Which broker did you download your mt4 from? I want to install it to test. 
 
Much thanks to you for your reaction, 

Indeed I'm not coder anyway I've had a go at coding a few EAs. My activity is associated with inventiveness and system so I conceptualized 600-700 thoughts for making EAs and constructed them till now. I simply can code simple EAs and I'm not used to your abnormal state coding... 

I've put those codes into my EA however it returns only this blunder: 2019.05.06 15:37:56.586 2018.01.02 00:00:07 MyEA! GBPAUD,H4: iTime(GBPUSD,240) Failed: 0 

I'm attempting GBPAUD as my opened diagram and GBPUSD as my second pair. 

What is the issue?