Juice StdDev with Histogram LA

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
Juice StdDev with Histogram  LA

This tool is designed to measure and visualize market volatility by calculating the Standard Deviation of price movements over a specific period. In simple terms, it helps traders understand how much the price is "swinging" or deviating from its average path.

How the Logic Works

1. Data Collection & Customization The script begins by looking at a user-defined timeframe (the "Period"). Instead of just looking at a single number, it analyzes a window of historical data to establish a baseline for how much the price normally fluctuates. You can choose which specific price points to track—such as the opening price, the closing price, the highs, or the lows—allowing the tool to be tailored to different trading styles.

2. Establishing the Average To determine what "normal" behavior looks like, the script first calculates a Moving Average. This represents the "center" of the price action for the chosen period. Think of this as the steady path the price wants to take.

3. Measuring the Deviation Once the average is established, the logic compares every individual price point within that period against that average. It calculates the difference between each point and the average, squares those differences (to ensure all values are positive), and sums them up. This tells the script how far away the current price action is "stretching" from the norm.

4. Final Calculation & Visualization The script then takes the square root of that total deviation to bring the number back into a readable scale. The final result is displayed as a Histogram in a separate window on your chart.

What this means for the trader

  • High Bars: When the histogram shows tall peaks, it indicates high volatility—the price is moving aggressively away from its average.
  • Low Bars: When the histogram remains low and flat, it suggests a "quiet" market where price action is stable and following the trend closely with very little fluctuation.

By using this logic, you can visually identify periods of intense market activity versus periods of calm consolidation without needing to manually calculate complex mathematical variances.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
Juice StdDev with Histogram LA
//+------------------------------------------------------------------+
//|                                           Standard Deviation.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_buffers 1
#property indicator_color1 LawnGreen
//---- input parameters
extern int ExtStdDevPeriod=6;
extern int ExtStdDevMAMethod=0;
extern int ExtStdDevAppliedPrice=0;
extern int ExtStdDevShift=0;
//---- buffers
double ExtStdDevBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string sShortName;
//---- indicator buffer mapping
   SetIndexBuffer(0,ExtStdDevBuffer);
//---- indicator line
   //---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1);
   //SetIndexDrawBegin(3,Level);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- line shifts when drawing
   SetIndexShift(0,ExtStdDevShift);   
//---- name for DataWindow and indicator subwindow label
   sShortName="StdDev("+ExtStdDevPeriod+")";
   IndicatorShortName(sShortName);
   SetIndexLabel(0,sShortName);
//----
   SetIndexDrawBegin(0,ExtStdDevPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Standard Deviation                                               |
//+------------------------------------------------------------------+
int start()
  {
   int i,j,nLimit,nCountedBars;
   double dAPrice,dAmount,dMovingAverage;  
//----
   if(Bars<=ExtStdDevPeriod) return(0);
//---- bars count that does not changed after last indicator launch.
   nCountedBars=IndicatorCounted();
//---- check for possible errors
   if(nCountedBars<0) return(-1);   
//----Standard Deviation calculation
   i=Bars-ExtStdDevPeriod-1;
   if(nCountedBars>ExtStdDevPeriod) 
     i=Bars-nCountedBars;  
   while(i>=0)
     {
       dAmount=0.0;
       dMovingAverage=iMA(NULL,0,ExtStdDevPeriod,0,ExtStdDevMAMethod,ExtStdDevAppliedPrice,i);
       for(j=0;j<ExtStdDevPeriod;j++)
          {
           dAPrice=GetAppliedPrice(ExtStdDevAppliedPrice,i+j);
           dAmount+=(dAPrice-dMovingAverage)*(dAPrice-dMovingAverage);
          }
       ExtStdDevBuffer[i]=MathSqrt(dAmount/ExtStdDevPeriod);
       i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetAppliedPrice(int nAppliedPrice, int nIndex)
  {
    double dPrice;
    switch(nAppliedPrice)
      {
       case 0:  dPrice=Close[nIndex];                                  break;
       case 1:  dPrice=Open[nIndex];                                   break;
       case 2:  dPrice=High[nIndex];                                   break;
       case 3:  dPrice=Low[nIndex];                                    break;
       case 4:  dPrice=(High[nIndex]+Low[nIndex])/2.0;                 break;
       case 5:  dPrice=(High[nIndex]+Low[nIndex]+Close[nIndex])/3.0;   break;
       case 6:  dPrice=(High[nIndex]+Low[nIndex]+2*Close[nIndex])/4.0; break;
       default: dPrice=0.0;
      }
    return(dPrice);
  }
//+------------------------------------------------------------------+

Comments