Zero divide error in strategy tester

To add comments, please log in or register
Batuhan Ortay
189
Batuhan Ortay  
accountBalanceinEuro = (int)(NormalizeDouble(AccountBalance(), 2) / NormalizeDouble(MarketInfo("EURTRY", MODE_ASK), 5));

I get "zero divide" error for this line.

EA is working on EURUSD.

How can I make the EA to read the EURTRY prices when working in strategy tester?

Francesco Rubeo
4304
Francesco Rubeo  
Batuhan:

I get "zero divide" error for this line.

EA is working on EURUSD.

How can I make the EA to read the EURTRY prices when working in strategy tester?

On strategy  tester to get access to other markets rates you have to use MqlRates.. Search for it and you will have your answer
Batuhan Ortay
189
Batuhan Ortay  
Francesco Rubeo:
On strategy  tester to get access to other markets rates you have to use MqlRates.. Search for it and you will have your answer


Thanks a lot.

Seng Joo Thio
547
Seng Joo Thio  
Batuhan:

I get "zero divide" error for this line.

EA is working on EURUSD.

How can I make the EA to read the EURTRY prices when working in strategy tester?

Based on what I know, when running within the strategy tester, you can only retrieve OHLC data of other pairs (i.e. one set of data per candle), not Ask and Bid prices, and not tick prices. But if you succeeded in doing so, please share how you do that, so I can learn too.

Alain Verleyen
38250
Alain Verleyen  
Francesco Rubeo:
On strategy  tester to get access to other markets rates you have to use MqlRates.. Search for it and you will have your answer

That's not exact. He can use MarketInfo, or SymbolInfoTick(). (see below).

Seng Joo Thio:

Based on what I know, when running within the strategy tester, you can only retrieve OHLC data of other pairs (i.e. one set of data per candle), not Ask and Bid prices, and not tick prices. But if you succeeded in doing so, please share how you do that, so I can learn too.

You can perfectly retrieve Bid/Ask from other pairs, if the data are available

So you have to check for errors.

Seng Joo Thio
547
Seng Joo Thio  
Alain Verleyen:

That's not exact. He can use MarketInfo, or SymbolInfoTick(). (see below).

You can perfectly retrieve Bid/Ask from other pairs, if the data are available

So you have to check for errors.

I hope you know what you're claiming, since you're not showing any code, and "if the data are available" is a rather vague statement that could either mean "sometimes", or "all the time"... LOL.

Alain Verleyen
38250
Alain Verleyen  
Seng Joo Thio:

I hope you know what you're claiming, since you're not showing any code, and "if the data are available" is a rather vague statement that could either mean "sometimes", or "all the time"... LOL.

Yes, if the data are available, it's pretty clear, nothing to do with time, nothing laughable. MT4 strategy tester doesn't download data automatically like MT5, so if you want to use other symbols you need to do it before running your test.

Just check it by yourself and provide the code if you want.

Seng Joo Thio
547
Seng Joo Thio  
Alain Verleyen:

Yes, if the data are available, it's pretty clear, nothing to do with time, nothing laughable. MT4 strategy tester doesn't download data automatically like MT5, so if you want to use other symbols you need to do it before running your test.

Just check it by yourself and provide the code if you want.

Right, then for the benefit of all who reads this thread, hope you're able to tell me what is wrong with my code or test procedure.

string mySymbols[] = {"AUDUSD","EURUSD","USDJPY"};
int numOfSymbols = 0;

int OnInit()
  {
   numOfSymbols = ArraySize(mySymbols);
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
  }

void OnTick()
  {
   MqlTick tick[];
   ArrayResize(tick,numOfSymbols);
   
   for (int i=0; i<numOfSymbols; i++)
   {
      if (!SymbolInfoTick(mySymbols[i],tick[i]))
         Print ("Error retrieving ", mySymbols[i], " tick information. Code: ", GetLastError());
      double bid = MarketInfo(mySymbols[i],MODE_BID);
      double ask = MarketInfo(mySymbols[i],MODE_ASK);
      Print ("i = ", i, ", Symbol = ", mySymbols[i], ", Bid = ", bid, ", Ask = ", ask, ", tick.bid = ", tick[i].bid, ", tick.ask = ", tick[i].ask);
   }      
  }

And for testing, I left the 3 charts - AUDUSD, EURUSD and USDJPY opened, set them to 1 minute, to be certain that the issue has nothing to do with history, and run the strategy tester on tick data for 24th May (last Friday), for each of the 3 pairs. Here're the screen captures:


It should be clear that using the codes above, Strategy Tester is only able to retrieve the Bid/Ask data for the pair that it runs on, not any other pair.

Alain Verleyen
38250
Alain Verleyen  
Seng Joo Thio:

Right, then for the benefit of all who reads this thread, hope you're able to tell me what is wrong with my code or test procedure.

And for testing, I left the 3 charts - AUDUSD, EURUSD and USDJPY opened, set them to 1 minute, to be certain that the issue has nothing to do with history, and run the strategy tester on tick data for 24th May (last Friday), for each of the 3 pairs. Here're the screen captures:


It should be clear that using the codes above, Strategy Tester is only able to retrieve the Bid/Ask data for the pair that it runs on, not any other pair.

You are right. I don't know why I was thinking it works, probably too accustomed with mql5 now. After checking some of my code I was effectively using close[0] to get current price of other symbols, which is obviously not the same.

Thanks, and sorry for the misleading information.

Batuhan Ortay
189
Batuhan Ortay  

My EA does not send orders and I just wanted to simulate it for correcting semantic bugs.

Eventually, I gave up to test it in strategy tester and tested it with real market data.

The discussion here is very helpful for me, thanks to all.

To add comments, please log in or register