Download MetaTrader 5

My iCustom code always return empty value (2147483647)----------------------(second edition)

To add comments, please log in or register
pacman992
32
pacman992  

this is the indicator code

#property indicator_buffers 2

double var_a[];
double var_b[];

int init(){
   SetIndexBuffer(0, var_a);
   SetIndexBuffer(1, var_b);
 
return (0);
}

int start(){

double getMainTrend;
double getMainTrend2;

getMainTrend = iMACD(NULL, Maintrend_TimeFrame, 8, 17, 9, PRICE_CLOSE, MODE_SIGNAL, 0); //assume this line is correct
getMainTrend2 = iMACD(NULL, Maintrend_TimeFrame, 8, 17, 9, PRICE_CLOSE, MODE_MAIN, 0); // this too

count = IndicatorCounted();
int pos = Bars - count;

while(pos-1>0)
   {
      var_a[pos]=getMainTrend;
      var_b[pos]=getMainTrend2;
	pos--; Alert("var_a = "+var_a[pos]+ " var_b = "+var_b[pos]); //this code return values
}

return (0);
}

int deinit(){
return (0);
}

 and this is the expert advisor

#property strict

int init(){
return(0);
}

int start(){
        double val_a = iCustom(NULL,0,"indicator",0,1); //i'm not sure about this line
	double val_b = iCustom(NULL,0,"indicator",1,1); //i'm not sure about this line
        alert("value A = "+ val_a); //this code return empty value
	alert("value B = "+ val_b); //this code return empty value

return(0);
}

int deinit(){
return(0);
}
Keith Watford
Moderator
10570
Keith Watford  

in your indicator, replace

while(pos-1>0)

with

while(pos>=0)

 

You are giving the same value to historical bars when starting the indicator

Did you intend this?

int start(){

int count = IndicatorCounted();
int pos = Bars - count;

while(pos>=0)
   {
      var_a[pos]=iMACD(NULL, 0, 8, 17, 9, PRICE_CLOSE, MODE_SIGNAL, pos);
      var_b[pos]=iMACD(NULL, 0, 8, 17, 9, PRICE_CLOSE, MODE_MAIN, pos);
        pos--; 
}

return (0);
}

 .

Doerk Hilger
1188
Doerk Hilger  

Hey there,

where is Maintrend_TimeFrame coming from? And when does it return 0, during backtest, live or when added in backtest to another EA? When added to strategy tester while you testing another EA, it cannot work, because the tester does not support other timeframes int such case, just btw. 

Doerk 

pacman992
32
pacman992  
GumRai:

in your indicator, replace

with

 

You are giving the same value to historical bars when starting the indicator

Did you intend this?

 .

thanks for the tip, but what i want to know is the parameter index at iCustom call
whroeder1
15592
whroeder1  
To add comments, please log in or register