Anybody know why it's not working?

 

Hi all,


Is anybody know why the attached file not working? In short I'm trying to use a dinamic MA_Period. And it's working in more simple codes below.


"test.mq4" (attached) is not working, please pay attention to "int MA_Period = perd(y);" line.


The dinamic MA Period is working in the codes below:

//+------------------------------------------------------------------+
//|                                                   SMA_custom.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DeepSkyBlue
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,0,2);
   SetIndexBuffer(0,ExtMapBuffer1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars-1;
   
   for(int i=limit;i>=0;i--)
   {
      ExtMapBuffer1[i]=iMA(Symbol(),0,perd(i),0,MODE_SMA,0,i);
   }
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

int perd(int y)
{
  double inval=iRSI(Symbol(),0,10,0,y);
  return(MathRound(inval/2));
}


I'm trying to put all codes here, but I get a "Too Long" alert. I really appreciate your help.


Thank you

Files:
test_1.mq4  6 kb
 

change

return(MathRound(inval/2));


to return(MathMax(7,MathRound(inval/2)));

 

WOW!!


You solve my problem for days in just a few moment. May I know how do you find the problem? So if I'll find the same problem in the future I won't bother you anymore.


Thank you!

 

sometime iRSI maybe is 0, Maybe 0 can not be used as parameter of MA.

So I use MathMax limit the parameter of MA to >=7

 

I see, I didn't know that before. Thanks for the new insight.

May I ask why "7"? I change it to "2", looks working too, anything else I don't know yet?


Thank you!