Download MetaTrader 5

Strategy Tester does not read past indicator data

To add comments, please log in or register
Jin
1539
Jin  

Hello, people.

Strategy tester does not read past indicator data. Is it right?? Is it a bug?? What am I doing wrong?

I'm writing an EA that needs to read past indicator data. It works just fine in Debugging mode, but it doesn't work when used in Strategy Test.

To illustrate, a prepared a simple EA example. It simply creates a file with the past data of MACD.

#include <Indicators\Oscilators.mqh>
#include <Indicators\TimeSeries.mqh>
//---
CiMACD m_MACD;
CiTime m_time;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   int m_handle=FileOpen("MACD.txt",FILE_WRITE|FILE_READ|FILE_ANSI);
//---
   m_MACD.Create("EURUSD",PERIOD_H2,12,24,9,PRICE_CLOSE);
   m_MACD.Refresh();
//---

   m_time.Create("EURUSD",PERIOD_H2);
   m_time.Refresh();
//---  
   for(int i=250;i>=0;i--)
     {
      FileWrite(m_handle,(string)m_time.GetData(i)+" .. "+(string)m_MACD.Main(i));
     }
//---        
   FileClose(m_handle);
   return(0);
  }

 

It works just fine in debug mode. See part of the MACD.txt created:

2012.07.20 02:00:00 .. 2.035336285732825e-005
2012.07.20 04:00:00 .. -5.09041097791485e-005
2012.07.20 06:00:00 .. -0.0001685180302035683
(...)
2012.08.17 18:00:00 .. 0.0004601803361685697
2012.08.17 20:00:00 .. 0.0004241007516783135
2012.08.17 22:00:00 .. 0.0003848867889622021

But when this EA is executed using the Strategy Tester (Date Begin: 2012.01.12 / End: 2012.08.01), you get:

2011.12.01 18:00:00 .. 1.797693134862316e+308
2011.12.01 20:00:00 .. 1.797693134862316e+308
2011.12.01 22:00:00 .. 1.797693134862316e+308
(...)
2011.12.30 18:00:00 .. 1.797693134862316e+308
2011.12.30 20:00:00 .. 1.797693134862316e+308
2011.12.30 22:00:00 .. 1.797693134862316e+308
 

The championship is coming and I can't optimize my EA.
Is it a bug???

Please, I would be gratefull for any help.

Thanks  

Jin
1539
Jin  

Hi again,

I have just found the reason why it is not resfreshing the indicator data inside the Strategy Tester.
It's because I'm trying to refresh inside the OnInit(). It works fine if you replace the routine to OnTick() event handler (with some flag control to execute just once). 

Anyway, I believe it's a suttle bug, and I will be reporting the bug to service desk, asking to be fixed. 

Thanks to all that tried to help.

Get in touch with developers using Service Desk!
Get in touch with developers using Service Desk!
  • www.mql5.com
We therefore attach great importance to all user reports about issues in our programs and try to answer each one of them.
Yoji
4
Yoji  

I concurr although for me it doesnt work in OnInit() either. Regardless the Indicator I try to use the Main(index) function will always return max double..
Yoji
4
Yoji  

Now even i got it :)


One has to call iCustom, CiBands.Create(..) ect in the OnInit() function and the rest in OnTick()!

Documentation on MQL5: Technical Indicators / iCustom
Documentation on MQL5: Technical Indicators / iCustom
  • www.mql5.com
Technical Indicators / iCustom - Documentation on MQL5
To add comments, please log in or register