Chaikin Volatility Code

 

hi

Im not familiar with MQL4 but I try to learn it. I have the Chaikins Volatility Code but Im unable to use it in my expert advisor. I just need

if (Chaikin>0)
  {
    ....CODE
  }

so here is the code from the chaikins indicator

#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DeepSkyBlue
 
//---- input parameters
extern int       iPeriod=10;
extern int       maPeriod=10;
//---- buffers
double chakin[];
double hl[];
double emahl[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,chakin);
   
   SetIndexBuffer(1,hl);
   SetIndexBuffer(2,emahl);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) counted_bars=0;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//----
   for(int c = 0 ;c <= limit ;c++) hl[c]=High[c]-Low[c];
   for(int e = 0 ;e <= limit ;e++) emahl[e]= iMAOnArray(hl,0,maPeriod,0,MODE_EMA,e);
   
   for(int i = 0 ;i <= limit-20 ;i++)
   {
      
      chakin[i] = ( (emahl[i]-emahl[i+iPeriod])/emahl[i+iPeriod] ) *100;  
   }
//----
   return(0);
  }

it would be nice if somone can transform this code so that I can integrate it in my expert advisor. thanks a lot!

regards

kalle

 
Write so
 
//---- input parameters of EA
extern int       iPeriod=10;
extern int       maPeriod=10;
 
....
 
start()
{
....
if (iCustom(NULL,0,"Chaikin",iPeriod,maPeriod,0,1)>0)
  {
   ....
  
  }
See also iCustom
 

thanks for your quick help. it seems to work :)

regards

kalle

 

hi

unfortunately it works at the beginning but the indicator returns "214783647" after a while (the usual numbers are -150.000 to +150.000). do you have any idea why it doesn't work correct?

regards

kalle

 

hello

I need some help. is it possible to give me the exact code for that

H-L (i) = HIGH (i) - LOW (i)
H-L (i - 10) = HIGH (i - 10) - LOW (i - 10)
CHV = (EMA (H-L (i), 10) - EMA (H-L (i - 10), 10)) / EMA (H-L (i - 10), 10) * 100

I only need the chaikin value for the current bar. I don't need to display a graph. I tried very hard but didn't find any solution...

regards

Kalle

Reason: