Download MetaTrader 5

Second newbie request

To add comments, please log in or register
mankin2006
20
mankin2006  
#property copyright "mankin"
#property link      ""

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

extern int Number=30;

double Line_Buffer[], Mean_Buffer[], RMS_Buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//--Line buffer
   SetIndexBuffer(0,Line_Buffer);
   SetIndexStyle(0,DRAW_LINE);
//--RMS and Mean Buffers
   SetIndexBuffer(1,Mean_Buffer);
   SetIndexBuffer(2,RMS_Buffer);
//--Line Name
   short_name="Prob("+Number+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//--Draw Line
   SetIndexDrawBegin(0,Number);   
   return(0);
  }

   
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i, counted_bars=IndicatorCounted();
   double Mean, RMS;
   //--
   if(Bars<=Number) return(0);
   //--
   if(counted_bars<1)
      for(i=1;i<=Number;i++) Line_Buffer[Bars-i]=0.0;
   //--
    i=Bars-Number-1;
   if(counted_bars>=Number) i=Bars-counted_bars-1;
   while(i>=0)
      {
      double Sum=0.0,Sum2=0.0;
      
         Sum+=MathLog(Close[i]/Open[i]);
         Sum2+=MathPow(MathLog(Close[i]/Open[i],2);
         
         Mean=Sum/Number;
         RMS=MathSqrt(Sum2/Number);
         
         Mean_Buffer[i]=Mean;
         RMS_Buffer[i]=RMS;
         
         Line_Buffer[i]=(((Mean/RMS)-(MathSqrt(Number)))+1)/2;
         i--;
      }
   
   

   
//----
   return(0);
  }
//+------------------------------------------------------------------+

1. How do I allow buffer line to show previous ticks in the history of the chart
2. Values in the indicator alone is not between 1 and 0
3. The indicator only shows values for current ticks- in other words, the whole indicator is blank when I first put into the terminal.

To add comments, please log in or register