Download MetaTrader 5

Help custom indicator causes mt4 to crash

To add comments, please log in or register
Do you need a programmer? Make an order to let the developer find you!
mankin2006
20
mankin2006 2013.12.17 11:19 
#property copyright "mankin"
#property link      ""

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 1
#property indicator_color1 Blue

extern int Number_Of_Bars =40;

double Prob_calc[];
double MA[];
double RMS[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,Prob_calc);
   SetIndexBuffer(1,MA);
   SetIndexBuffer(2,RMS);
   //--Lines
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexDrawBegin(0,Number_Of_Bars);
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double Aver,
   Root,
   Aver_Sq; 
   
   if(Bars<=Number_Of_Bars) return(0);
   
   if(counted_bars<1) 
      for(i=1;i<=Number_Of_Bars;i++) Prob_calc[Bars-i]=0.0;
   
//----
   i=Bars-Number_Of_Bars-1;
   
   if(counted_bars>=Number_Of_Bars) i=Bars-counted_bars-1;
   
   while(i>=1)
      {
         double Sum=0.0,Sum_Sq=0.0;
         if(i==Bars-Number_Of_Bars-1)
            {
               int n=Bars-2;
               
                 Sum+=Close[n];
                 Sum_Sq+=MathPow(Close[n],2);
            }
            
            Aver=Sum/Number_Of_Bars;
            Aver_Sq=Sum_Sq/Number_Of_Bars;
            
            
            
      }
      
      Root=MathSqrt(Aver_Sq);
      MA[i]=Aver;
      RMS[i]=Root;
      
      Prob_calc[i]=((Aver/Root)-(1/MathSqrt(Number_Of_Bars))+1)/2;
      i--;
      
//----
   return(0);
  }

//+------------------------------------------------------------------+
Here's the sourc ecode
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.12.17 11:30  
Abcogito:
Here's the sourc ecode

How does i become less than 1 ?

   while(i >= 1)    // infinite loop . . . .
      {
         double Sum=0.0,Sum_Sq=0.0;
         if(i == Bars - Number_Of_Bars - 1)
            {
               int n = Bars - 2;
               
                 Sum += Close[n];
                 Sum_Sq += MathPow(Close[n],2);
            }
            
            Aver = Sum / Number_Of_Bars;
            Aver_Sq = Sum_Sq / Number_Of_Bars;
            
            
            
      }
To add comments, please log in or register