Help With Indicator Calculation

 

Hi,

I am trying to code the RelativeSlope indi.

The Rslp buffer always returns a "zero"when it is just a 3 periode EMA of the PLOT1 buffer.

I would appreciate some advice about what is causing this issue.


Thanks in advance


#property  indicator_separate_window

#property  indicator_buffers 2
#property  indicator_color1  Red
#property  indicator_color2  Blue

extern int Periodo=12;

double     PLOT1[];//Temporal
double     Rlsp[];

int init()
  {

   SetIndexBuffer(0,PLOT1);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(1,Rlsp);
   SetIndexStyle(1,DRAW_LINE);

   return(0);
  }

int start()
  {
  double EMA1, EMA2,EMA3;
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(int i=0; i<limit; i++)
   {
   EMA1=iMA(NULL,0,Periodo,0,MODE_EMA,PRICE_TYPICAL,i);
   EMA2=iMA(NULL,0,Periodo,0,MODE_EMA,PRICE_TYPICAL,i+1);
   EMA3=(2*(EMA1-EMA2)/(EMA1+EMA2));
   PLOT1[i]=EMA3;
   }
   
   for(i=0; i<limit; i++)
   {
    Rlsp[i]=iMAOnArray(PLOT1,Bars,3,0,MODE_EMA,i);//ALWAYS ZERO HERE
    Print(Rlsp[i]);
   }
  

   return(0);
  }
 

How many elements are there in your . . .

PLOT1 and Rlsp Arrays ?

 

Hi,

I guess you mean that the PLOT1 array could be substitute by a single variable. It seems to me that there shouldn´t be a problem in saving the variable EMA3 in an array. And then, create another with a 3 periode EMA.

In terms of MQL, at the point I am, I can not figure out why I am getting a zero value.

I am following the same structure as other indicators (for instant the custom macd that is by default in the terminal), but I am doing something wrong.

¿Could you give me another clue? I must be missing something really basic.


Thanks

 
CJS:


Hi,

I guess you mean that the PLOT1 array could be substitute by a single variable.

No, what I actually meant was . . . How many elements re there in your arrays ? 1, 10, 1000 ? or maybe 0 ? how many ?

Have a read of this, it will help you : https://book.mql4.com/variables/arrays

 
RaptorUK:

How many elements are there in your . . .

PLOT1 and Rlsp Arrays ?

those are not explicitly user-defined arrays. They are intended as output buffers, and recommended better names (like PLOT1Buffer, etc).

and this line:

 Rlsp[i]=iMAOnArray(PLOT1,Bars,3,0,MODE_EMA,i);-----> replace Bars with 0, if the whole array is what you want?
 
diostar:

those are not explicitly user-defined arrays. They are intended as output buffers, and recommended better names (like PLOT1Buffer, etc).

and this line:

Ah . . . good point. Sorry . . . my mistake.
 

Hi,

Is working fine now.

Also my mistake for using confusing names. I take note of the recommendation

Thanks a lot.