Download MetaTrader 5

Retrieving values of indicator buffer

To add comments, please log in or register
How to buy a product in MetaTrader AppStore? Read the article!
Samuel Oyeniyi
376
Samuel Oyeniyi 2015.06.05 13:46 

I get this error message while trying to retrieve  values of an indicator. The indicator is working properly and can return those value in itself:

 

2015.06.05 05:34:49.405 TestEA5 (EURUSD,M5) S Abufer_d[] 0=179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,ABuffer_4h 0=17976931348623157000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

 

Can somebody please point what I am missing or doing wrong. 

//+------------------------------------------------------------------+
//|                                                     Signal01.mqh |
//|                       "Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright ""Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#include <Expert\ExpertSignal.mqh>
// wizard description start
//+------------------------------------------------------------------+
//| Description of the class                                          |
//| Title=Signals of indicator 'Pitchfork_A'                           |
//| Type=SignalAdvanced                                               |
//| Name=Pitchfork_A                                                   |
//| ShortName=Pitchfork_A                                              |
//| Class=CSignalPitchfork_A                                           |
//| Page=signal_Pitchfork_A                                            |
//| Parameter=a,int,12,ExtDepth                                       |
//| Parameter=b,int,5, ExtDeviation                                   |
//| Parameter=c,int,3, ExtBackstep                                    |
//+------------------------------------------------------------------+
// wizard description end
//+------------------------------------------------------------------+
//| Class CSignalPitchfork_A.                                          |
//| Purpose: Class of generator of trade signals based on            |
//|          the 'Pitchfork_A' indicator.                              |
//| Is derived from the CExpertSignal class.                         |
//+------------------------------------------------------------------+
class CSignalPitchfork_A : public CExpertSignal
  {
protected:
   CiCustom       m_Pitchfork_A;            // object-indicator - Pitchfork_A
   //--- adjusted parameters
   int               m_a;      // the "ExtDepth" parameter of the indicator
   int               m_b;       // the "ExtDeviation" parameter of the indicator
   int               m_c;      // the "ExtBackstep" parameter of the indicator
   //--- "weights" of market models (0-100)
   int               m_pattern_0;      // model 0 "price has pulled back"
   int               m_pattern_1;      // model 1 "price crossed a border of the envelope"

public:
                     CSignalPitchfork_A(void);
                    ~CSignalPitchfork_A(void);
   //--- methods of setting adjustable parameters
   void              a(int value)                   { m_a=value;        }
   void             b(int value)                    { m_b=value;        }
   void              c(int value)                   { m_c=value;        }
   //--- methods of adjusting "weights" of market models
   void              Pattern_0(int value)                { m_pattern_0=value;        }
   void              Pattern_1(int value)                { m_pattern_1=value;        }
  
   //--- method of verification of settings
   virtual bool      ValidationSettings(void);
   //--- method of creating the indicator and timeseries
   virtual bool      InitIndicators(CIndicators *indicators);
   //--- methods of checking if the market models are formed
   virtual int       LongCondition(void);
   virtual int       ShortCondition(void);

protected:
   //--- method of initialization of the indicator
   bool              InitPitchfork_A(CIndicators *indicators);
   //--- methods for getting data

   //- getting the indicator value
   double            Main(int ind) { return(m_Pitchfork_A.GetData(0,ind));      } 
   double            ABuffer_d(int ind) { return(m_Pitchfork_A.GetData(3,ind));      }
   double            ABuffer_4h(int ind) { return(m_Pitchfork_A.GetData(4,ind));      }     
   double            ABuffer_1h(int ind) { return(m_Pitchfork_A.GetData(5,ind));      } 
   double            BBuffer_d(int ind) { return(m_Pitchfork_A.GetData(6,ind));      } 
   double            BBuffer_4h(int ind) { return(m_Pitchfork_A.GetData(7,ind));      } 
   double            BBuffer_1h(int ind) { return(m_Pitchfork_A.GetData(8,ind));      }          
  };
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CSignalPitchfork_A::CSignalPitchfork_A(void) :
                                           m_a(12),
                                           m_b(5),
                                           m_c(3),
                                           m_pattern_0(100),
                                           m_pattern_1(0)
  {
//--- initialization of protected data
   m_used_series=USE_SERIES_OPEN+USE_SERIES_HIGH+USE_SERIES_LOW+USE_SERIES_CLOSE;
  }

//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CSignalPitchfork_A::~CSignalPitchfork_A(void)
  {
  }
//+------------------------------------------------------------------+
//| Validation settings protected data.                              |
//+------------------------------------------------------------------+
bool CSignalPitchfork_A::ValidationSettings(void)
  {
//--- validation settings of additional filters
   if(!CExpertSignal::ValidationSettings())
      return(false);
//--- initial data checks
   if(m_a<=0)
     {
      printf(__FUNCTION__+": ExtDepth must be greater than 0");
      return(false);
     }
//--- ok
   return(true);
  }
//+------------------------------------------------------------------+
//| Create indicators.                                               |
//+------------------------------------------------------------------+
bool CSignalPitchfork_A::InitIndicators(CIndicators *indicators)
  {
//--- check pointer
   if(indicators==NULL)
      return(false);
//--- initialization of indicators and timeseries of additional filters
   if(!CExpertSignal::InitIndicators(indicators))
      return(false);
//--- create and initialize Pitchfork_A indicator
   if(!InitPitchfork_A(indicators))
      return(false);
//--- ok
   return(true);
  }
//+------------------------------------------------------------------+
//| Initialization of indicators.                                    |
//+------------------------------------------------------------------+
bool CSignalPitchfork_A::InitPitchfork_A(CIndicators *indicators)
  {
//--- add an object to the collection
   if(!indicators.Add(GetPointer(m_Pitchfork_A)))
     {
      printf(__FUNCTION__+": error adding object");
      return(false);
     }
//--- set parameters of the indicator
   MqlParam parameters[4];
//---
   parameters[0].type=TYPE_STRING;
   parameters[0].string_value="Pitchfork_A.ex5";
   parameters[1].type=TYPE_INT;
   parameters[1].integer_value=12;
   parameters[2].type=TYPE_INT;
   parameters[2].integer_value=5;
   parameters[3].type=TYPE_INT;
   parameters[3].integer_value=3;
//--- object initialization
   if(!m_Pitchfork_A.Create(m_symbol.Name(),0,IND_CUSTOM,4,parameters))
    {
      printf(__FUNCTION__+": error initializing object");
      return(false);
     }
//--- number of buffers
   if(!m_Pitchfork_A.NumBuffers(9)) return(false);
//--- ok
   return(true);
  }
 
 
//+------------------------------------------------------------------+
//| "Voting" that price will grow.                                   |
//+------------------------------------------------------------------+
int CSignalPitchfork_A::LongCondition(void)
  {
 
   int result=0;
  
 
    m_Pitchfork_A.Refresh();
   int idx   =StartIndex();
  
     double close_d=m_Pitchfork_A.GetData(6,0);
     double close_4h=m_Pitchfork_A.GetData(7,0);
     double close_1h=m_Pitchfork_A.GetData(8,0);

              
  Print( "L BBuffer_d 0="+ DoubleToString(m_Pitchfork_A.GetData(6,0),0)+","+"BBuffer_4h 0="+ DoubleToString(m_Pitchfork_A.GetData(7,0),0)+","+"BBuffer_1h 0="+ DoubleToString(m_Pitchfork_A.GetData(8,0),0));


//--- if the model 0 is used and price is in the rollback zone, then there is a condition for buying
   if ( ((close_d==2) || (close_4h==2) || (close_1h==2)) ) //IS_PATTERN_USAGE(0) &&
      result=m_pattern_0;
//--- if the model 1 is used and price is above the rollback zone, then there is a condition for buying
  // if(IS_PATTERN_USAGE(1) && close>upper+m_limit_out*width)
   //   result=m_pattern_1;
//--- return the result
   return(result);
  }
  

    
  
//+------------------------------------------------------------------+
//| "Voting" that price will fall.                                   |
//+------------------------------------------------------------------+
int CSignalPitchfork_A::ShortCondition(void)
  {
   int result  =0;
    m_Pitchfork_A.Refresh();
   int idx     =StartIndex();
   //int close=m_Pitchfork_A.GetData(0,0);
     double close_d=m_Pitchfork_A.GetData(3,0);
     double close_4h=m_Pitchfork_A.GetData(4,0);
     double close_1h=m_Pitchfork_A.GetData(5,0);

            
Print("S Abufer_d[] 0="+ DoubleToString(m_Pitchfork_A.GetData(3,0),0)+","+"ABuffer_4h 0="+ DoubleToString(m_Pitchfork_A.GetData(4,0),0)+","+"ABuffer_1h 0="+ DoubleToString(m_Pitchfork_A.GetData(5,0),0));
//--- if the model 0 is used and price is in the rollback zone, then there is a condition for selling
   if  (  ((close_d==1) || (close_4h==1) || (close_1h==1)) )//( ((TimeCurrent()-objtime)<=7200) )//IS_PATTERN_USAGE(0) && &&
      result=m_pattern_0;
//--- if the model 1 is used and price is above the rollback zone, then there is a condition for selling
   //if(IS_PATTERN_USAGE(1) && close<lower-m_limit_out*width)
     // result=m_pattern_1;
//--- return the result
   return(result);
  }
//+------------------------------------------------------------------+
To add comments, please log in or register