Download MetaTrader 5

Invalid pointer access error

To add comments, please log in or register
Stephen Njuki
5205
Stephen Njuki  

Hi


My EA compiles well but on debugging it throws up this error prior to any trade. How does one access h1 volume? Below are excerpts of my source

//+------------------------------------------------------------------+
//|                                                       Signal.mqh |
//|                                            Copyright © 2010, SSN |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Expert\ExpertSignal.mqh>

//+------------------------------------------------------------------+
class CSignal : public CExpertSignal
  {
protected:
   CiVolumes         *m_Ticks;

        //

public:
                     CSignal();
          
   //---
        //
   virtual bool      InitIndicators(CIndicators *indicators);
        //

protected:
   bool              InitTicks(CIndicators *indicators);
        //
   //---
   double            Ticks(int ind)       { return(m_Ticks.Main(ind));} //THIS IS WHERE I GET THE ERROR "INVALID POINTER ACCESS"
        //
  };

void CSignal::CSignal()
  {
//--- initialize protected data
   m_Ticks     =NULL;
        //
  }



bool CSignal::InitIndicators(CIndicators *indicators)
  {
   if(!InitTicks(indicators))    return(false);
        //
//--- ok
   return(true);
  }

bool CSignal::InitTicks(CIndicators *indicators)
  {
   
//--- create fast EMA indicator and add it to collection
   if(m_Ticks==NULL)
      if((m_Ticks=new CiVolumes)==NULL)
         return(false);
   if(!indicators.Add(m_Ticks))
      return(false);
//--- initialize MA indicator
   if(!m_Ticks.Create(m_symbol.Name(),PERIOD_H1,VOLUME_TICK))
      return(false);
//--- ok
   return(true);
  }

int CSignal::InitVolumes()
   {  
      

      //THIS IS HOW I WOULD LIKE TO USE THE TICK VOLUME...

      ticks=0;
      for(i=1;i<period;i++)
      {
         ticks+=Ticks(i);
      }
      
        //
      
      return(P);
   }

//
 

Alexey Da
Moderator
6568
Alexey Da  
ssn:

Hi


My EA compiles well but on debugging it throws up this error prior to any trade. How does one access h1 volume? Below are excerpts of my source

Could you attach full source code? It helps us to check your message faster.
Stephen Njuki
5205
Stephen Njuki  
Here is the source that gets the pointer error
//+------------------------------------------------------------------+
//|                                                       Signal.mq5 |
//|                                               Copyright 2010,SSN |
//|                                                                  |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Expert\ExpertSignal.mqh>
class CSignal : public CExpertSignal
  {
protected:

   CiTickVolume              *m_Ticks;
   CiVolumes         *m_volumes;
   
   double            m_adjusted_point;             // point value adjusted for 3 or 5 points
   
   CSymbolInfo       m_symbol;                     // symbol info object\

public:
                     CSignal();
                        
   //---
   virtual bool      Init(CSymbolInfo* symbol,ENUM_TIMEFRAMES period,double adjusted_point);
   virtual bool      InitIndicators(CIndicators *indicators);
   //---

protected:
   
   int               InitPeriods(string speed);
   bool              InitTicks(CIndicators *indicators);
   bool              InitVolumes(CIndicators *indicators);
   //---
public:
   long              Ticks(int ind)     { return(m_Ticks.GetData(ind));     }
   double              Tvolumes(int ind)     { return(m_volumes.Main(ind));     }
  };
  
CSignal signal;

void CSignal::CSignal()
  {
//--- initialize protected data
   m_Ticks     =NULL;
   m_volumes  =NULL;
  }
  
bool CSignal::Init(CSymbolInfo* symbol,ENUM_TIMEFRAMES period,double adjusted_point)
  {
   
   if(CheckPointer(m_Ticks)==POINTER_INVALID)
     {
      printf("CSignal: ticks Pointer is invalid, EA halted");
      return(false);
     }
   
   if(CheckPointer(m_volumes)==POINTER_INVALID)
     {
      printf("CSignal: volumes Pointer is invalid, EA halted");
      return(false);
     }
//--- ok
   return(true);
  }
  
bool CSignal::InitIndicators(CIndicators *indicators)
  {
   if(!InitTicks(indicators))    return(false);
   
   if(!InitVolumes(indicators))   return(false);
//--- ok
   return(true);
  }
  
bool CSignal::InitTicks(CIndicators *indicators)
  {
//--- create volume indicator and add it to collection
   if(m_Ticks==NULL)
      if((m_Ticks=new CiTickVolume)==NULL)
         return(false);
   if(!indicators.Add(m_Ticks))
      return(false);
//--- initialize volume indicator
   if(!m_Ticks.Create(m_symbol.Name(),PERIOD_M1))
      return(false);
//--- ok
   return(true);
  }
  
bool CSignal::InitVolumes(CIndicators *indicators)
  {
//--- create volume indicator and add it to collection
   if(m_volumes==NULL)
      if((m_volumes=new CiVolumes)==NULL)
         return(false);
   if(!indicators.Add(m_volumes))
      return(false);
//--- initialize volume indicator
   if(!m_volumes.Create(m_symbol.Name(),PERIOD_H1,VOLUME_TICK))
      return(false);
//--- ok
   return(true);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
      int i,p;
      long ticks;
      double volumes;
      
      p=7; 
      
      ticks=0;
      volumes=0;
      for(i=1;i<p;i++)
      {
         ticks+=signal.Ticks(i);
         volumes+=signal.Tvolumes(i);
      }
         
      Print(" ticks : ",ticks
      ," volumes r : ",volumes);
   
  }
//+------------------------------------------------------------------+

Here is also a snap of my journal



Rashid Umarov
Admin
12265
Rashid Umarov  
Alexey Da
Moderator
6568
Alexey Da  
ssn:
Here is the source that gets the pointer error

Here is also a snap of my journal

Look at this. You are trying to get access to NULL pointer.

 

 

Stephen Njuki
5205
Stephen Njuki  

Thanks for your comments, I was able to resolve that.


I now have another problem. Having upgraded to build 350, My strategy tester cannot run any tests despite having all the relevant price data.

I get this message in my journal

2010.10.30 13:01:04    Core 1    EURUSD,Daily: 0 ticks (0 bars) generated within 0 ms (total bars in history 311)


...there are 'no errors' as well...? what could be the problem?


Alexey Da
Moderator
6568
Alexey Da  
ssn:

Thanks for your comments, I was able to resolve that.


I now have another problem. Having upgraded to build 350, My strategy tester cannot run any tests despite having all the relevant price data.

I get this message in my journal

2010.10.30 13:01:04    Core 1    EURUSD,Daily: 0 ticks (0 bars) generated within 0 ms (total bars in history 311)


...there are 'no errors' as well...? what could be the problem?


Have you tried to recompile your EA?

Is your problem reproducing now? 

To add comments, please log in or register