Download MetaTrader 5

invalid pointer access error

To add comments, please log in or register
Copy the deals of successful traders. Subscribe to signals!
dudenukem
57
dudenukem 2011.11.18 00:17 

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.
Alexey Da
Moderator
6598
Alexey Da 2011.11.18 11:55  

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. 

Rashid Umarov
Admin
11812
Rashid Umarov 2011.11.18 12:11  
dudenukem
57
dudenukem 2011.11.19 19:07  
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);
  }

dudenukem
57
dudenukem 2011.11.22 00:34  

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
Alexey Da
Moderator
6598
Alexey Da 2011.11.22 10:53  
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. 

dudenukem
57
dudenukem 2011.11.27 20:44  

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


Files:
k_orders.mqh 11 kb
kiwi_v3.mq5 6 kb
onnewbar.mqh 3 kb
To add comments, please log in or register