iCustom indicator does not load correctly

 
Hi,

I have managed to load the custom indicator and it partly plots on the graph when using the strategy tester. However the actual curve line does not seem to plot for some reason. Below is the code:

//+------------------------------------------------------------------+
//|                             Stochastic_CCI_Bollinger_Band_V2.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

// User inputted variables

input int                inpCciPeriod       = 32;            // CCI period
input ENUM_APPLIED_PRICE inpCciPrice        = PRICE_TYPICAL; // Price
input int                inpStoPeriod       = 32;            // Stochastic period
input int                inpStoSlowing      = 9;             // Stochastic slowing period
input double             inpLevelDown       = 20;            // Level down

// Handles && Buffers

double  values[],values_calculated[],level_up[],level_dn[],price[],cci_values[],sto_values[];

int StochasticCciHandle;

string mSymbol;
ENUM_TIMEFRAMES mTimeframe;
int mBarCount;
int mPrevCalculated;
datetime previousBarTime;

// Testing entry signals

string signal="";

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int OnInit()
  {
  
   mSymbol = _Symbol;
   mTimeframe = PERIOD_CURRENT;
   StochasticCciHandle = iCustom(NULL,Period(),"CCI_Stochastic.ex5",20,40,PRICE_CLOSE);
   
   return(INIT_SUCCEEDED);
  }
  
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if(StochasticCciHandle != INVALID_HANDLE){
      IndicatorRelease(StochasticCciHandle);
   }
  }

void OnTick()
  {
   // Populating indicator values
   
   ArraySetAsSeries(values,true);
   ArraySetAsSeries(values_calculated,true);
   ArraySetAsSeries(level_up,true);
   ArraySetAsSeries(level_dn,true);
   ArraySetAsSeries(price,true);
   ArraySetAsSeries(cci_values,true);
   ArraySetAsSeries(sto_values,true);
 
   CopyBuffer(StochasticCciHandle,0,0,3,level_up);
   CopyBuffer(StochasticCciHandle,1,0,3,level_dn);
   CopyBuffer(StochasticCciHandle,2,0,3,values);
   CopyBuffer(StochasticCciHandle,3,0,3,values_calculated);
   CopyBuffer(StochasticCciHandle,4,0,3,price);
   CopyBuffer(StochasticCciHandle,5,0,3,cci_values);
   CopyBuffer(StochasticCciHandle,6,0,3,sto_values);
}


Indicator Code:

//+------------------------------------------------------------------+
//|                                               CCI_Stochastic.mq5 |
//|                   Copyright 2009-2017, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "© mladen, 2018"
#property link      "mladenfx@gmail.com"
#property version   "1.00"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_plots   3
#property indicator_label1  "up level"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrLimeGreen
#property indicator_style1  STYLE_DOT
#property indicator_label2  "down level"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrOrange
#property indicator_style2  STYLE_DOT
#property indicator_label3  "value"
#property indicator_type3   DRAW_COLOR_LINE
#property indicator_color3  clrSilver,clrLimeGreen,clrOrange
#property indicator_width3  2
//
//---
//
input int                inpCciPeriod       = 32;            // CCI period
input ENUM_APPLIED_PRICE inpCciPrice        = PRICE_TYPICAL; // Price
input int                inpStoPeriod       = 32;            // Stochastic period
input int                inpStoSlowing      = 9;             // Stochastic slowing period
input double             inpLevelUp         = 80;            // Level up
input double             inpLevelDown       = 20;            // Level down
                                                             //
//---
//
double  val[],valc[],levelUp[],levelDn[],prices[],cci[],sto[];
//------------------------------------------------------------------
//
//------------------------------------------------------------------
void OnInit()
  {
   SetIndexBuffer(0,levelUp,INDICATOR_DATA);
   SetIndexBuffer(1,levelDn,INDICATOR_DATA);
   SetIndexBuffer(2,val,INDICATOR_DATA);
   SetIndexBuffer(3,valc,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(4,prices,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,cci,INDICATOR_CALCULATIONS);
   SetIndexBuffer(6,sto,INDICATOR_CALCULATIONS);
   for(int i=0; i<2; i++) PlotIndexSetInteger(i,PLOT_SHOW_DATA,false);
   IndicatorSetString(INDICATOR_SHORTNAME,"CCI - Stochastic ("+(string)inpCciPeriod+","+(string)inpStoPeriod+")");
  }
//------------------------------------------------------------------
//
//------------------------------------------------------------------
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[])
  {
   if(Bars(_Symbol,_Period)<rates_total) return(-1);

   int i=(int)MathMax(prev_calculated-1,0); for(; i<rates_total && !_StopFlag; i++)
     {
      prices[i]  = getPrice(inpCciPrice,open,close,high,low,i,rates_total);
      double avg = 0; for(int k=0; k<inpCciPeriod && (i-k)>=0; k++) avg +=         prices[i-k];      avg /= inpCciPeriod;
      double dev = 0; for(int k=0; k<inpCciPeriod && (i-k)>=0; k++) dev += MathAbs(prices[i-k]-avg); dev /= inpCciPeriod;

      //
      //---
      //

      cci[i]=(dev!=0) ?(prices[i]-avg)/(0.015*dev) : 0;
      int _start= MathMax(i-inpStoPeriod+1,0);
      double hh = cci[ArrayMaximum(cci,_start,inpStoPeriod)];
      double ll = cci[ArrayMinimum(cci,_start,inpStoPeriod)];
      sto[i]     = (hh!=ll) ? 100*(cci[i]-ll)/(hh-ll) : 0;
      val[i]     = 0; for(int k=0; k<inpStoSlowing && (i-k)>=0; k++) val[i] += sto[i-k];  val[i] /= inpStoSlowing;
      levelUp[i] = inpLevelUp;
      levelDn[i] = inpLevelDown;
      valc[i]    = (val[i]>levelUp[i]) ? 1 : (val[i]<levelDn[i]) ? 2 : (i>0) ? (val[i]==val[i-1]) ? valc[i-1]: 0 : 0;
     }
   return(i);
  }
//+------------------------------------------------------------------+
//| Custom functions                                                 |
//+------------------------------------------------------------------+
double getPrice(ENUM_APPLIED_PRICE tprice,const double &open[],const double &close[],const double &high[],const double &low[],int i,int _bars)
  {
   switch(tprice)
     {
      case PRICE_CLOSE:     return(close[i]);
      case PRICE_OPEN:      return(open[i]);
      case PRICE_HIGH:      return(high[i]);
      case PRICE_LOW:       return(low[i]);
      case PRICE_MEDIAN:    return((high[i]+low[i])/2.0);
      case PRICE_TYPICAL:   return((high[i]+low[i]+close[i])/3.0);
      case PRICE_WEIGHTED:  return((high[i]+low[i]+close[i]+close[i])/4.0);
     }
   return(0);
  }
//+------------------------------------------------------------------+

What is expected Vs What happens (Please see attached screenshots)

I feel as though the curve is being plotted as though the values are always zero for some reason but I am not sure why. Should I be calling the getPrice function from the indicator code in my EA?

Thanks

Files:
 
Jameson947:
Hi,

I have managed to load the custom indicator and it partly plots on the graph when using the strategy tester. However the actual curve line does not seem to plot for some reason. Below is the code:


Indicator Code:

What is expected Vs What happens (Please see attached screenshots)

I feel as though the curve is being plotted as though the values are always zero for some reason but I am not sure why. Should I be calling the getPrice function from the indicator code in my EA?

Thanks

you need to write the whole path, as the documentation says

Documentación para MQL5: Indicadores técnicos / iCustom
Documentación para MQL5: Indicadores técnicos / iCustom
  • www.mql5.com
iCustom - Indicadores técnicos - Manual de referencia de MQL5 - manual de usuario para el lenguaje del trading algorítmico/automático para MetaTrader 5
 
Javier Santiago Gaston De Iriarte Cabrera #:

you need to write the whole path, as the documentation says

Could you please elaborate on what you mean by the full path?

It does load in the tester but the curve line value remains at 0 for some reason. If you see the screen shot you will understand the error. The journals do not generate any error code when running the code