invalid pointer access error

 

I wanted to play with the example from

MQL5 Wizard: How to Create a Module of Trading Signals

https://www.mql5.com/en/articles/226

and wanted to implement it in my own EA; unfortunately I get the invalid pointer access in 'SampleSignal.mqh' (151,20) in the file

samplesignal.mqh


the code from my EA using the samplesignal.mqh is

:

CIndicators* pIndTimeSer;// = new CIndicators();
CSampleSignal oSignal;
MqlTradeRequest sTradeReq;//temporary store parameters of a trade
double iccaVal[]; //this holds the logical value for the controller class
Order objOrder;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
     pIndTimeSer = new CIndicators();
      //check the pointer:
         if(CheckPointer(pIndTimeSer)==POINTER_INVALID)
             Print(__FUNCTION__," the variable 'pIndTimeSer' isn't initialized!");
             
      oSignal.ValidationSettings(); 
      oSignal.InitIndicators(pIndTimeSer);
....

still cannot resolve the error...any suggestions are welcome!

MQL5 Wizard: How to Create a Module of Trading Signals
  • 2011.01.11
  • MetaQuotes Software Corp.
  • www.mql5.com
The article discusses how to write your own class of trading signals with the implementation of signals on the crossing of the price and the moving average, and how to include it to the generator of trading strategies of the MQL5 Wizard, as well as describes the structure and format of the description of the generated class for the MQL5 Wizard.
 

Does the message "OnInit the variable 'pIndTimeSer' isn't initialized!" appear when you execute your code? I think It would have been nice if you had exited from OnInit function with result not equal 0.

Have you implemented check for POINTER_INVALID before using pointer on the line 151? 

It is very difficult to give you any helpful advice before you show the full source of your EA. 

 

See also the article Using the Object Pointers in MQL5
 
alexvd:

Does the message "OnInit the variable 'pIndTimeSer' isn't initialized!" appear when you execute your code? I think It would have been nice if you had exited from OnInit function with result not equal 0.

Have you implemented check for POINTER_INVALID before using pointer on the line 151? 

It is very difficult to give you any helpful advice before you show the full source of your EA. 

here is the code for my EA - its just the OnInit() as I was trying to see if the signal class will be compiled and will run.

I've implemented POINTER_INVALID check before line 151; the pointeris fine and the error remains


#include <..\Libraries\cisnewbar.mqh>  //source mql5.com
#include <Signal\MySignals\SampleSignal.mqh>  //class signals for MA and for implementing strategy
#include <onnewbar.mqh>  //on new bar event handler
#include <k_orders.mqh> //the order class for executing orders
//+------------------------------------------------------------------+
//| Our signals object to handle the trades                          |
//+------------------------------------------------------------------+
//CIndicators* pIndTimeSer;
CIndicators* pIndTimeSer;// = new CIndicators();
CSampleSignal oSignal;
MqlTradeRequest sTradeReq;//temporary store parameters of a trade
double iccaVal[]; //this holds the logical value for the controller class
Order objOrder;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
     pIndTimeSer = new CIndicators();
      //check the pointer:
         if(CheckPointer(pIndTimeSer)==POINTER_INVALID)
             Print(__FUNCTION__," the variable 'pIndTimeSer' isn't initialized!");
             
      oSignal.ValidationSettings(); 
      oSignal.InitIndicators(pIndTimeSer);
      //init trade to use in Signal

      
//---
   return(0);
  }

 

the following pointer m_symbol is not initialized:

if(CheckPointer(m_symbol)==POINTER_INVALID)
             Print(__FUNCTION__," the variable 'm_symbol' isn't initialized!");
             
   if(!m_MA.Create(m_symbol.Name(),m_period,m_period_ma,m_shift_ma,m_method_ma,m_applied_ma

produces the error invalid pointer:


2011.11.21 21:29:39    Core 1    2011.10.01 00:00:00   CSampleSignal::InitMA the variable 'm_symbol' isn't initialized!

...

Documentation on MQL5: MQL5 programs / Runtime Errors
  • www.mql5.com
MQL5 programs / Runtime Errors - Documentation on MQL5
 
dudenukem:

the following pointer m_symbol is not initialized:

produces the error invalid pointer:


2011.11.21 21:29:39    Core 1    2011.10.01 00:00:00   CSampleSignal::InitMA the variable 'm_symbol' isn't initialized!

...


Could you provide a full source?

I need to see where and how you are initializing your object.

Please do not forget to provide all includes and libraries. 

 

here are all the files from my test EA (kiwi_v3).


Files:
cisnewbar.mqh  8 kb
k_orders.mqh  11 kb
kiwi_v3.mq5  6 kb
onnewbar.mqh  3 kb