How can the prices series and indicator values contained in the CSignalXXXX Class generated by the MQL5 Wizard be successfully accessed?

 
Dear All,

  Let me illustrate my problem in MACD.

  After I used MQL5 wizard to create a very simple EA based on the signals of CSignalMACD indicator.

I made 2 changes to it:

1. In SignalMACD.mqh, add a member function PrintDBgInfo() to CSignalMACD,which print the Open, Time, and MACD's main and signal line.

2. At the end of the wizard created OnInit() function I call the PrintDbgInfo() function.But result was obviously wrong. As in the following figure.I used debugger to debug the code. It seems that price series and the indicator values are not correctly calculated, or maybe even worse, they are not correctly initialized.

What's  wrong? What modification should I make for accessing the price series and indicator values correctly, or how should i initialize CSignalMACD?

Thank you for your prompt reply.
void CSignalMACD::PrintDbgInfo()
{
  for (int i=0;i<=10;i++)
  {
    double d_open, d_main,d_signal;
    datetime dt;
    d_open=Open(i);
    d_main=Main(i);
    d_signal=Signal(i);
    dt=Time(i);
    Print(i,",Open=",d_open,
    ",Time=",TimeToString(dt,TIME_DATE|TIME_MINUTES),
    ",Main=",DoubleToString(d_main,6),
    ",signal=",DoubleToString(d_signal,6));
  }
}
Files:
 
taozemin:
Dear All,

  Let me illustrate my problem in MACD.

  After I used MQL5 wizard to create a very simple EA based on the signals of CSignalMACD indicator.

I made 2 changes to it:

1. In SignalMACD.mqh, add a member function PrintDBgInfo() to CSignalMACD,which print the Open, Time, and MACD's main and signal line.

2. At the end of the wizard created OnInit() function I call the PrintDbgInfo() function.But result was obviously wrong. As in the following figure.I used debugger to debug the code. It seems that price series and the indicator values are not correctly calculated, or maybe even worse, they are not correctly initialized.

What's  wrong? What modification should I make for accessing the price series and indicator values correctly, or how should i initialize CSignalMACD?

Thank you for your prompt reply.
Place your code in OnTick() not in OnInit().
 
angevoyageur:
Place your code in OnTick() not in OnInit().

Dear angevoyageur:

   Thank you for your prompt reply. I am sorry that The problem still exist. I've moved the function PrintDbgInfo() into a function , and this function will be called by a function called by OnTick() (the code is attached in the files below) . But the output of PrintDbgInfo() is not we anticipated.

  As shown in the two figures below. The Open value is unreasonably big. the Time() is always d'1970/01/01'.The Main and signal value of the MACD indicator is much bigger than that shown in the Data Window....


the output of the print function in the "expert" tab.


Data shown in the data window after pressing ctrl+D.



Files:
 
taozemin:

Dear angevoyageur:

   Thank you for your prompt reply. I am sorry that The problem still exist. I've moved the function PrintDbgInfo() being by a function call, and this function will be called by OnTick(). But the output is not we anticipated (the code is attached below) . But the output of PrintDbgInfo() is not we anticipated.As shown in the two figures below. The Open value is unreasonable big. the Time() is always d'1970/01/01'.The Main and signal value of the MACD indicator is much bigger than shown in the Data Window.


Where is the call to PrintDbgInfo() now ?

...
   //signal.PrintDbgInfo();
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ExtExpert.Deinit();
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()    ???
  {
   ExtExpert.OnTick();
  }

Your timeseries aren't initialized (open & time).

Your MACD is just fine, but you are dividing the value by _Point when you print them.

 
angevoyageur:

Where is the call to PrintDbgInfo() now ?

Your timeseries aren't initialized (open & time).

Your MACD is just fine, but you are dividing the value by _Point when you print them.


Dear angevoyageur:

Thank you for  your prompt reply.
1. the call to PrintDbgInfo is in CheckOpenLong(), this function will be called by bool CExpert::Processing().You can set a break point in it and step to PrintDbgInfo().
bool CSignalMACD_TMP::CheckOpenLong(double& price,double& sl,double& tp,datetime& expiration)
{
  PrintDbgInfo();
  return(false);
}

2. I used to  think the function Onit() generated by the wizard will make all the initialization for time series and indicadtor. So I retained almost all the statements in the OnInit() function generated by the MQL wizard. But the output is still not incorrect.......

So the core to the question is:

2.1). how should we initialize the CSignalMACD, and the time series?

2.2). how can we access these information to analyze the chart?

If the two questions are solved, then we can find a way to a more interesting problem: how to maximally reuse the code generated by MQL 5 wizard to customize the market entry logic?

3. I deleted the call to /_Point, but the out put is still incorrect, a line in the output is as follows:

2014.04.22 06:58:21.390    wizard created 03 (EURUSD,M1)    10,Open=1.797693134862316e+308,Time=1970.01.01 00:00,Main=-0.0000,signal=-0.0000

4. Time series initialization:

   at the end of the OnInit() function , a call is made to CExpert's InitIndicators() member function ,which in turn calls CExpertBase::InitIndicators(CIndicators *indicators). in this function, all time series are initialized, as follows:

bool CExpertBase::InitIndicators(CIndicators *indicators)
  {
//--- this call is for compatibility with the previous version
   if(!ValidationSettings())
      return(false);
//--- check the initialization phase
   if(m_init_phase!=INIT_PHASE_VALIDATION)
     {
      printf(__FUNCTION__+": parameters of setting are not checked");
      return(false);
     }
   if(!m_other_symbol && !m_other_period)
      return(true);
//--- check pointers
   if(m_symbol==NULL)
      return(false);
   if(indicators==NULL)
      return(false);
//--- initialization of required timeseries
   if(IS_OPEN_SERIES_USAGE && !InitOpen(indicators))
      return(false);
   if(IS_HIGH_SERIES_USAGE && !InitHigh(indicators))
      return(false);
   if(IS_LOW_SERIES_USAGE && !InitLow(indicators))
      return(false);
   if(IS_CLOSE_SERIES_USAGE && !InitClose(indicators))
      return(false);
   if(IS_SPREAD_SERIES_USAGE && !InitSpread(indicators))
      return(false);
   if(IS_TIME_SERIES_USAGE && !InitTime(indicators))
      return(false);
   if(IS_TICK_VOLUME_SERIES_USAGE && !InitTickVolume(indicators))
      return(false);
   if(IS_REAL_VOLUME_SERIES_USAGE && !InitRealVolume(indicators))
      return(false);
//--- initialization of object (from the point of view of the base class) has been performed successfully
//--- now it's impossible to change anything in the settings
   m_init_phase=INIT_PHASE_COMPLETE;
//--- ok
   return(true);
  }