Use of Indicator inside an EA gives wrong data. Please help

 

Good day.

I have designed an EA where I use the cross of 2 indicators (one is an iCustom, the other just an iMA) to generate trading signals. I want to use the data generated by the iCustom indicator as the applied_price in the iMA. Problem is that the iMA, when I use the icustom generated data as the applied_price, only returns the values of the PRICE_CLOSE (ie it plainly ignores the applied_price). I would very much appreciate some help, please as this is getting me real crazy.

here is the  code:

 SNRIndic=iCustom(NULL,0,"SNR1IND",0,0); //---- generates indicator values to be used in the iMA below
 AvExpo=iMA(NULL,0,AvPeriod,0,MODE_EMA,SNRIndic,0);

I have checked and the iCustom really returns the SNRIndic that I created as custom indicator, however, the iMA does only return the EMA value of the Price close. 

Thanks!!

 
alg2013:

Good day.

I have designed an EA where I use the cross of 2 indicators (one is an iCustom, the other just an iMA) to generate trading signals. I want to use the data generated by the iCustom indicator as the applied_price in the iMA. Problem is that the iMA, when I use the icustom generated data as the applied_price, only returns the values of the PRICE_CLOSE (ie it plainly ignores the applied_price). I would very much appreciate some help, please as this is getting me real crazy.

here is the  code:

 SNRIndic=iCustom(NULL,0,"SNR1IND",0,0); //---- generates indicator values to be used in the iMA below
 AvExpo=iMA(NULL,0,AvPeriod,0,MODE_EMA,SNRIndic,0);

I have checked and the iCustom really returns the SNRIndic that I created as custom indicator, however, the iMA does only return the EMA value of the Price close. 

Thanks!!

Read the documentation for iMA()  you have 7 options for the APPLIED PRICE ,  SNRIndic  isn't one of them.

You need to write your values from your iCustom() call to a buffer/array and then use iMAOnArray() with that buffer/array. 

 

Thanks!! I will give it a go (I am just new to MQL4 programming, so very much appreciated your help)

 

RaptorUK, hi

After a few tries I was able to succesfully program & insert the iMAOnArray() function into my EA. Problem now is that it returns values that are different from the ones obtained when I insert the iMA on the Indicator screen (the values that I get with the iCustom indicator are similar to the ones on the screen, though, so the problem seems to be with the values reurned by the iMAOnArray()).

Here is the code. This code is placed prior to the routine that checks for open and close conditions

  double SNRIndic;
   double SNR1_buffer[100];
   double AvExpoArray[100];
//---- go trading only for first tiks of new bar
  if(Volume[0]>1) return;
//---- get Indicators data
  
   SNRIndic=iCustom(NULL,0,"SNR1IND",0,0);
  
   int    i, limit=PeriodSNR; 
   ArraySetAsSeries(SNR1_buffer,true);
  
   for(i=0; i<limit; i++)
      {
      SNR1_buffer[i]=iCustom(NULL,0,"SNR1IND",0,0);
      }
  
   for(i=0; i<limit; i++)
      {
      AvExpoArray[i]=iMAOnArray(SNR1_buffer,0,AvPeriod,0,MODE_EMA,0);
      }

Also, I have noted that alll values in the array are the same, ie. AvExpoArray[1] returns the same value as AvExpoArray[7]. Is this correct?.

In fact I am using arbitrarily one of those array values to trigger buy and sell signals (my buy/sell logic is a crossover of both indicators, ie  

if (SNRIndic < AvExpoArray[1])  then a buy/sell signal is triggered. I fear that the arbitrary use of [1] or other subindex is making the results different, but honestly dont know how to check this.

 Any help will be welcome.

alg2013 

 
alg2013:

RaptorUK, hi

After a few tries I was able to succesfully program & insert the iMAOnArray() function into my EA. Problem now is that it returns values that are different from the ones obtained when I insert the iMA on the Indicator screen (the values that I get with the iCustom indicator are similar to the ones on the screen, though, so the problem seems to be with the values reurned by the iMAOnArray()).

Here is the code. This code is placed prior to the routine that checks for open and close conditions

 <CODE REMOVED>

 

Please edit your post . . . 

 

Use SRC 

 
alg2013:

Also, I have noted that alll values in the array are the same, ie. AvExpoArray[1] returns the same value as AvExpoArray[7]. Is this correct?.

ofcours that is correct you are giving them same values

 for(i=0; i<limit; i++)
      {
      SNR1_buffer[i]=iCustom(NULL,0,"SNR1IND",0,0);
      }

if you made it like .....

SNR1_buffer[i]=iCustom(NULL,0,"SNR1IND",0,i);

it might be like you wanted

 

Hi DeVries, thanks for your help. I have tried and now it is worse as the calculated value is 0.

Here is the code again

double SNRIndic, AvExpo;
   double SNR1_buffer[100];
   double AvExpoArray[100];
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//---- get Indicators data 
   
   SNRIndic=iCustom(NULL,0,"SNR1IND",0,0);// this is the first indicator. Values are calculated correctly
   
   int    i,limit=PeriodSNR; //limit=ArraySize(SNR1_buffer);
   ArraySetAsSeries(SNR1_buffer,false);
   
   for(i=0; i<limit; i++)
      {
      SNR1_buffer[i]=iCustom(NULL,0,"SNR1IND",0,0);
      }
   
   for(i=0; i<limit; i++)
      {
      AvExpoArray[i]=iMAOnArray(SNR1_buffer,0,AvPeriod,0,MODE_EMA,i);
      }

 So, when I apply the buy/sell criteria as a crossover of SNRIndic and the iMAOnArray result using PeriodSNR as the shift length (or any other value for that matter)...

 if (SNRIndic < AvExpoArray[PeriodSNR])

 ... the returned value for AvExpoArray[] is 0. what am I doing wrong?

Also, I want the crossover calculation being on teh current bar (bar 0). For this, what is the number that I have to put in brackets in AvExpoArray[]?

Thanks!! 

 
for(i=0; i<limit; i++)
      {
      SNR1_buffer[i]=iCustom(NULL,0,"SNR1IND",0,0);
      }

This is always giving the same value  look to it

for(i=0; i<limit; i++)
      {
      SNR1_buffer[i]=iCustom(NULL,0,"SNR1IND",0,0);
         Print("SNR1_buffer[",i,"]=   ",DoubleToStr(SNR1_buffer[i],Digits));
      }

 if you calculate the average high of  always the same number then it will be that number

 I suggested to calculate 

SNR1_buffer[i]=iCustom(NULL,0,"SNR1IND",0,i);

in the loop does this make a difference ???

 

Hi deVries, thanks for your help. Interesting and strange: I just did it, and checked the SNR1_buffer[i] values and it produces values other than 0 (great!).. However the following command

for(i=0; i<limit; i++)
      {
      AvExpoArray[i]=iMAOnArray(SNR1_buffer,0,AvPeriod,0,MODE_EMA,i);
      }

will still be 0 for any value of [i] in the iMAOnArray[i] formula when I print it. Thus I cannot still cross both indicators...

 
alg2013:

Hi deVries, thanks for your help. Interesting and strange: I just did it, and checked the SNR1_buffer[i] values and it produces values other than 0 (great!).. However the following command

will still be 0 for any value of [i] in the iMAOnArray[i] formula when I print it. Thus I cannot still cross both indicators...

 


what value has AvPeriod in the loop ??

Print it to be sure... 

 

Printed it and value was 2 (for some strange reason). Then I set it up upfront as AvPerio=14 and when printed again, now it was 14 (correct). However, still iMAOnArray[AvPeriod] returned 0.

thanks again... 

Reason: