MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Automated Trading and Strategy Testing Forum

Rabbit Indicator
Rabbit
Author: Jon_Katana
Multi Symbol Price DivergenceMulti Symbol Price Divergence Try product
Multi Symbol Price Divergence
Author: tol64
Subscribe to signal
FOREX GURU
20.06%, 1 200.60 USD
Screenshot
LLS, H1
Demo
New Article Publishing System at the MQL5.community New Article Publishing System at the MQL5.community

// Strategy Tester does not read past indicator data

To add comments, please log in or register
Jin
1470
Jin 2012.08.19 08:40 

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
1470
Jin 2012.08.19 18:21  

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.

 

Yoji
4
Yoji 2012.09.18 11:41  

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 2012.09.19 02:46  

Now even i got it :)


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

/
To add comments, please log in or register