DRAW_NONE affects vertical scale

 

Hi

I want to display 3 indicators in separate window but show those and a 4th value in data window. Everything works except that the scale of the 4th value causes the display of the first 3 values to be crammed together. How do I prevent the 4th value from affecting the vertical scale of the display window? Suggestions gratefully received.

//+------------------------------------------------------------------+
//|                                              StDev & LinRegSlope |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DarkGray
#property indicator_color2 Blue
#property indicator_color3 Red

#property indicator_level3 0

//---- input parameters
extern int StdDevPeriod=6;

//---- buffers
double ATRBuffer[];
double StdDevBuffer[];
double LinRegSlopeBuffer[];
double xxxBuffer[];

double pipper;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
        if(Digits==2 || Digits==4) pipper=Point;
        if(Digits==3 || Digits==5) pipper=10*Point;
  
   IndicatorShortName("StDev & Slope("+StdDevPeriod+")");
   
   IndicatorBuffers(4);
   
   //STYLE
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_NONE);
   
   // Mapping
   SetIndexBuffer(0,ATRBuffer);
   SetIndexBuffer(1,StdDevBuffer);
   SetIndexBuffer(2,LinRegSlopeBuffer);
   SetIndexBuffer(3,xxxBuffer);
   
   // Label
   SetIndexLabel(0,"ATR(14,"+StdDevPeriod+")");
   SetIndexLabel(1,"StdDev("+StdDevPeriod+")");
   SetIndexLabel(2,"LinRegSlope("+StdDevPeriod+")");
   SetIndexLabel(3,"ATR/SD");


   return(0);
  }
//+------------------------------------------------------------------+
//| Standard Deviation, Slope,                                       |
//+------------------------------------------------------------------+
/*
Some Notes:
I use x and y (to represent time and price) because I find it easier to
visualise the Linear Regression Line plotted on xy co-ordinates.

               y = Slope * x + yIntercept formula.


The upper-case E represents the Greek sigma (for SUM)
 - thus Exx means the sum of the x-squareds.

*/

int start()
  {
   
   int    i,j,x,CountedBars;
   double y,Yavg,diff,SSdiffs,Ex,Ey,Exy,Exx;
   
//---- insufficient data
   if(Bars<=StdDevPeriod) return(0);
   
//---- count of bars that have not changed since last indicator launch
   CountedBars=IndicatorCounted();
   
//----Calculation
   i=Bars-StdDevPeriod-1;
   if(CountedBars>StdDevPeriod) i=Bars-CountedBars;
   
   while(i>=0)
     {
      Yavg=iMA(NULL,0,StdDevPeriod,0,MODE_SMA,PRICE_CLOSE,i);
      
      SSdiffs=0.0;Ex=0.0;Ey=0.0;Exy=0.0;Exx=0.0;   //Initialise accumulators to zero
      
      for(j=1; j<=StdDevPeriod; j++)
        {
         x        =  i+StdDevPeriod-j;
         y        =  Close[x];
         diff     =  y-Yavg;
         
         SSdiffs  += diff*diff;
         Ex       += x;
         Ey       += y;
         Exy      += x*y;
         Exx      += x*x;
        }
      
      // ATR as measured from a point before the StdDevPeriod
//      ATRBuffer[i]         = MathRound(iATR(NULL,0,5,i+StdDevPeriod)/pipper);
      ATRBuffer[i]         = iATR(NULL,0,5,i+StdDevPeriod);
      
      // Sample standard deviation (using Bessel's correction)
//      StdDevBuffer[i]      = MathRound(MathSqrt(SSdiffs/(StdDevPeriod-1))/pipper);
      StdDevBuffer[i]      = MathSqrt(SSdiffs/(StdDevPeriod-1));
      
      
      // Uses ABS because don't care whether slope is up or down
//      LinRegSlopeBuffer[i] = MathRound(MathAbs((StdDevPeriod*Exy - Ex*Ey) / (StdDevPeriod*Exx - Ex*Ex))/pipper);
      LinRegSlopeBuffer[i] = MathAbs((StdDevPeriod*Exy - Ex*Ey) / (StdDevPeriod*Exx - Ex*Ex));
      

if(StdDevBuffer[i] != 0.0) double xxx = ATRBuffer[i]/StdDevBuffer[i]; else xxx=.09999;
xxxBuffer[i] = xxx;
      
      // yIntercept formula is included here just in case
      double yIntercept = ( Ey*Exx - Ex*Exy ) / ( StdDevPeriod*Exx - Ex*Ex );
      
      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
onedognight:

Hi

I want to display 3 indicators in separate window but show those and a 4th value in data window. Everything works except that the scale of the 4th value causes the display of the first 3 values to be crammed together. How do I prevent the 4th value from affecting the vertical scale of the display window? Suggestions gratefully received.

If the values are not important to you and you just use the 4th value visually then you will need to scale it's values so it fits within the range of the other 3 values. Unfortunately there is no option to have Y axis scales on the left as well as on the right, just one Y axis is available.
 
onedognight:

I want to display 3 indicators in separate window but show those and a 4th value in data window. Everything works except that the scale of the 4th value causes the display of the first 3 values to be crammed together. How do I prevent the 4th value from affecting the vertical scale of the display window? Suggestions gratefully received.

I assume you mean that the code works fine as posted, but (a) you have to change #property indicator_buffers to 4 to make the ATR/SD appear in the data window, and then (b) doing that alters the scale of the indicator.

I haven't had to try anything like this before, but it would appear that you can keep the values in the data window while preventing the line from affecting the scale of the indicator by using SetIndexDrawBegin(). For example, adding SetIndexDrawBegin(3, 999999999); seems to work in terms of keeping the data values, but completely suppressing any aspect of the drawing.
 
onedognight:



Thanks jjc; that worked!
Reason: