Cannot find out what's wrong with my code

Back to topics list To post a new topic, please log in or register
avatar
2
anddm 2015.03.26 22:47
 

Hi guys!


I am trying to code the Chaikin Volatility indicator. I know that there is plenty of examples of such an indicator, but my point now is to understand what I am missing and whether I misunderstood how to code in MQL4.

The problem I am encoutering is the following: no data is drawn in the chart window, nothing. And I cannot see where is the problem because the debugger simply says everything is ok (0 errors, 0 warnings).

Please, help me! This is driving me crazy!

Thanks in advances for any comment you will post.


Here my code:

#property strict

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  Yellow
#property indicator_width1  1
#property indicator_color2  Gold
#property indicator_width2  1

#include <MovingAverages.mqh>
    
input int                  InpChaikinPeriod = 10;               
input int                  InpChaikinShift = 10;    

double CHV[];
double CHVMA[];


//+------------------------------------------------------------------+


int OnInit()
{
   IndicatorDigits(5);
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,CHV);   
   SetIndexLabel(0,"Chaikin Volatility");  
   IndicatorShortName("CHV");
   
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(1,CHVMA);   
   SetIndexLabel(1,"Chaikin MA");  
   IndicatorShortName("CHVMA");

   return(INIT_SUCCEEDED);

}


//+------------------------------------------------------------------+

  
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[])
{
  
   ArraySetAsSeries(CHV,false);
   ArraySetAsSeries(CHVMA,false);
   ArraySetAsSeries(open,false);
   ArraySetAsSeries(high,false);
   ArraySetAsSeries(low,false);
   ArraySetAsSeries(close,false);
   
   int i,pos;

   double EMA_HL[];
   double HL[];   
   
   if ( prev_calculated<1 ) {
      for(i=0; i<InpChaikinPeriod; i++) { CHV[i]=0.0; }
      }
     
   pos = InpChaikinPeriod - 1;

   if ( prev_calculated>InpChaikinPeriod ) pos = prev_calculated-1;
   
   for ( i=0; i<rates_total; i++ ) { HL[i] = high[i] - low[i]; }
      
   ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpChaikinPeriod,HL,EMA_HL);
      
   for ( i=pos; i < rates_total; i++ ) { 
      CHV[i] = ( EMA_HL[i] - EMA_HL[i-InpChaikinShift] ) / EMA_HL[i-InpChaikinShift]*100;
      }  

   SimpleMAOnBuffer(rates_total,prev_calculated,0,InpChaikinPeriod,CHV,CHVMA);
  
   return(rates_total); 
         
}
avatar
Moderator
3406
GumRai 2015.03.27 00:32 #
 

   double EMA_HL[];
   double HL[];  

 You do not size these arrays

avatar
2
anddm 2015.03.27 11:52 #
 
GumRai:

 You do not size these arrays

I need them to be dynamic arrays. Isn't it the way to declare dynamic arrays?

Plus, I have also tried the following two codes, and even though HL and EMA_HL are plotted, no trace of CHV and CHVMA yet.

#property indicator_buffers 4

...

double CHV[];
double CHVMA[];
double EMA_HL[];
double HL[];

int OnInit()
{
   ...
   SetIndexBuffer(2,EMA_HL);
   SetIndexBuffer(3,HL);
   ...

}


//-----------------
// or also
//-----------------


int OnCalculate(...)
{
   ...
   ArrayResize(EMA_HL,rates_total);
   ArrayResize(HL,rates_total);
   ...

}
Back to topics list  

To add comments, please log in or register