CUSTOM INDICATOR AUTOSCALE & GRAPHING OF HISTORY

 
I have written a few custom indicators in MetaEditor and cannot seem to find a way to make the Y-Axis auto scale... I keep having to go back into the program to change the scale manualy as the indicator output value changes... below is my code... what would I change to make this indicator auto-scale the the Y-Axis? Also, when I load the indicator it only graphs data from the time when I loaded forward... my other indicators draw a line as far back as the price history goes... how might I fix that Issue?

**Note: The indicator below is designed to plot the bandwidth between the upper and lower bollinger bands.**

Thanks,
Ryan


/+------------------------------------------------------------------+
//| 20 2.0 Band Width of Bollinger Bands Ghostriser.mq4 |
//| Copyright © 2006, Ghostrider Capital LLC. |
//| ryanjmcgregor@tds.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Ghostrider Capital LLC."
#property link "ryanjmcgregor@tds.net"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 DodgerBlue
#property indicator_maximum .01
#property indicator_minimum 0


//---- indicator parameters
extern int BandsPeriod=20;
extern int BandsShift=0;
extern double BandsDeviations=2.0;
//---- buffers
//---- Moving, Upper, and Lower are for counting to draw Band Width 20
double BandWidth20Buffer[];
double MovingBuffer[];
double UpperBuffer[];
double LowerBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,DodgerBlue );
SetIndexBuffer(0,BandWidth20Buffer);
SetIndexLabel(0,"Band Width 20");

SetIndexBuffer(1,MovingBuffer);

SetIndexBuffer(2,UpperBuffer);

SetIndexBuffer(3,LowerBuffer);

//---- 4 Indicators Buffers Mapping
SetIndexDrawBegin(0,BandsPeriod+BandsShift);
SetIndexDrawBegin(1,BandsPeriod+BandsShift);
SetIndexDrawBegin(2,BandsPeriod+BandsShift);
SetIndexDrawBegin(3,BandsPeriod+BandsShift);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2 );
IndicatorShortName("Band Width of 20 2.0 BB");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Bollinger Bands |
//+------------------------------------------------------------------+
int start()
{
int i,k,counted_bars=IndicatorCounted();
double deviation;
double sum,oldval,newres,upper,lower,middle;

//----
if(Bars<=BandsPeriod) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=BandsPeriod;i++)
{
MovingBuffer[Bars-i]=EMPTY_VALUE;
UpperBuffer[Bars-i]=EMPTY_VALUE;
LowerBuffer[Bars-i]=EMPTY_VALUE;
BandWidth60Buffer[Bars-i]=EMPTY_VALUE;
}
//----
int limit=Bars-counted_bars;
if(counted_bars>0) limit++;
for(i=0; i<limit; i++)
MovingBuffer[i]=iMA(NULL,0,BandsPeriod,BandsShift,MODE_SMA,PRICE_ CLOSE,i);

//----
i=Bars-BandsPeriod+1;
if(counted_bars>BandsPeriod-1) i=Bars-counted_bars-1;
while(i>=0)
{
sum=0.0;
k=i+BandsPeriod-1;
oldval=MovingBuffer[i];
while(k>=i)
{
newres=Close[k]-oldval;
sum+=newres*newres;
k--;
}
deviation=BandsDeviations*MathSqrt(sum/BandsPeriod);
UpperBuffer[i]=oldval+deviation;
LowerBuffer[i]=oldval-deviation;


//---- Formula Band Width = (Upper - Lower) / Middle Band moving sma
BandWidth20Buffer[i]=(UpperBuffer[i]-LowerBuffer[i])/MovingBuffer[i];

i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
 
please use MQL button to publish your sources