Problem using a Custom Indicator from an EA.

 

Hello,

I have just write my first very simple custom indicator (returns -1 or +1 for candlestick of a determined size) . It can be added mannually to a chart properly, but I have problems using it from an EA.  The think is that when I test and visualize the EA, the indicator is shown well in the chart of the visual test window and a positive number is the result of iCustom call, and everything is ok, BUT when I add the compiled EA to a chart, the indicator does not appairs, and -1 is the result of the iCustom call. Any idea about why???  

Thanks in advance.

Juan


EA INDICATOR CALL CODE

oninit

{

.....

   ArrayResize(ics_array, ics_array_size); 
 ics = iCustom(NULL, 0,  "i1//iCandleSignal",  i_white_size,  i_white_size_range);
 Comment(IntegerToString(ics));

 ChartIndicatorAdd(handlex, 0, ics);

ChartRedraw(handlex);

...

}
  INDICATOR CODE
#include <MovingAverages.mqh>

//+------------------------------------------------------------------+
//|                                                           i4.mq5 |
//|                                                        tacticals |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "tacticals"
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   1
//--- plot p_i
#property indicator_label1  "p_i"
#property indicator_type1   DRAW_COLOR_HISTOGRAM
#property indicator_color1  clrRed,clrGreen,clrBlue,clrYellow,clrMagenta,clrCyan,clrMediumSeaGreen,clrGold
#property indicator_style1  STYLE_SOLID
#property indicator_width1  3
//--- input parameters
double input size= 0.0010;
double input tolerance = 0.0005;
//--- indicator buffers
double         p_iBuffer[];
double         p_iColors[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,p_iBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,p_iColors,INDICATOR_COLOR_INDEX);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int pos;
//--- start calculation
   pos=prev_calculated-1;
   for(int i= 1;i<rates_total;i=i+1)
   {     
      double v = close[i]-open[i];     
      if
      (
         (MathAbs(v) < (size + tolerance))
         &&
         (MathAbs(v) >= size)
      )
      {
         if
         (
            (v > 0)
         )
         {
            p_iBuffer[i]= 1;
            p_iColors[i]= 2;
         }
         else
         {
            p_iBuffer[i]= -1;
            p_iColors[i]= 0;
         };
      }
      else
         p_iBuffer[i]= 0;     
   }
   return(rates_total);
  }
//+------------------------------------------------------------------+
Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator
Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator
  • 2010.04.07
  • Denis Zyatkevich
  • www.mql5.com
MetaQuotes Programming Language 5 (MQL5), included in MetaTrader 5 Client Terminal, has many new possibilities and higher performance, compared to MQL4. This article will help you to get acquainted with this new programming language. The simple examples of how to write an Expert Advisor and Custom Indicator are presented in this article. We will also consider some details of MQL5 language, that are necessary to understand these examples.
 
Please EDIT your post, when posting code you have to use SRC button.
 
angevoyageur:
Please EDIT your post, when posting code you have to use SRC button.

Thanks for your answer, and sorry for the wrong edition of the post.

 
jbru:

Thanks for your answer, and sorry for the wrong edition of the post.

So why don't you edited your post. I do it for you this time.
 
jbru:

Hello,

I have just write my first very simple custom indicator (returns -1 or +1 for candlestick of a determined size) . It can be added mannually to a chart properly, but I have problems using it from an EA.  The think is that when I test and visualize the EA, the indicator is shown well in the chart of the visual test window and a positive number is the result of iCustom call, and everything is ok, BUT when I add the compiled EA to a chart, the indicator does not appairs, and -1 is the result of the iCustom call. Any idea about why???  

Thanks in advance.

Juan

...

What is that value of handlex variable  ?

 ChartIndicatorAdd(handlex, 0, ics);
 
ics = iCustom(NULL, 0,  "i1//iCandleSignal",  i_white_size,  i_white_size_range);

The third parameter could be wrong. You should change it to:

ics = iCustom(NULL, 0,  "i1\\iCandleSignal",  i_white_size,  i_white_size_range);