Volatility_Pivot

Download script
Author: thanks to S.B.T. (Japan)
Volatility_Pivot

This tool is designed to help traders visualize market volatility and identify structural price boundaries by calculating a dynamic "trailing" stop level. Rather than relying on static numbers, it adapts to the current movements of the market to provide a more fluid view of price action.

Core Logic and Functionality

The script operates based on three primary components: Volatility Measurement, Mode Selection, and the Dynamic Pivot calculation.

1. Volatility Assessment The underlying logic begins by measuring how much the price is currently fluctuating. It looks at a historical window of data to determine the "Average True Range." This allows the tool to distinguish between a quiet market with small movements and a high-activity market with large price swings.

2. Operational Modes The script offers two distinct ways to calculate the distance of its pivot line:

  • Dynamic Mode: The tool takes the current volatility measurement and applies a multiplier. This means that when the market becomes more violent, the buffer between the price and the indicator expands; when the market calms down, the buffer shrinks.
  • Fixed Mode: The tool ignores volatility fluctuations and uses a set, predetermined price distance to maintain the pivot level.

3. Pivot Point Tracking The most important feature of this script is how it handles the "Stop" line. It behaves like a smart tracker that follows the price:

  • Trend Persistence: If the price remains consistently on one side of the line, the indicator maintains its current position or moves slightly to accommodate the trend without resetting.
  • Price Interaction: If the price closes on the opposite side of the previous level, the script triggers a recalculation. It establishes a new "floor" or "ceiling" based on the current close price plus or minus the volatility buffer.
  • Smoothing: By using an exponential moving average on the volatility data, the tool ensures that the resulting line is smooth and doesn't jump erratically from one candle to the next.

Summary for Traders

In essence, this script creates a reactive boundary line on your chart. It automatically "breathes" with the market—widening during high-stress periods and tightening during lulls. It serves as a visual aid to help identify when a trend might be exhausting or when a significant price pivot has occurred, providing a data-driven way to visualize support and resistance levels that evolve in real-time.

Indicators Used
Indicator of the average true rangeMoving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Volatility_Pivot
//+------------------------------------------------------------------+
//|                                             Volatility.Pivot.mq4 |
//+------------------------------------------------------------------+
#property copyright "thanks to S.B.T. (Japan)"
#property link      "http://sufx.core.t3-ism.net/" //<<< convert this from VT, thanks mate !!!
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
//---- input parameters
extern double     atr_range=100;
extern double     ima_range=10;
extern double     atr_factor=3;
extern int        Mode=0;
extern double     DeltaPrice=30;
//---- buffers
double TrStop[];
double ATR[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexBuffer(0,TrStop);
   SetIndexStyle(1,DRAW_NONE);
   SetIndexBuffer(1,ATR);
//----
   string short_name="!! RisenbergVolatilityCapture";
   IndicatorShortName(short_name);
   SetIndexLabel(1,"range base");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i;
//----
   double DeltaStop;
//----
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+1;

   for(i=0; i<limit; i++)
     {
      ATR[i]=iATR(NULL,0,atr_range,i);
     }
   for(i=limit-1; i>=0; i --)
     {
      if(Mode==0)
        {
         DeltaStop=iMAOnArray(ATR,0,ima_range,0,MODE_EMA,i)*atr_factor;
         //DeltaStop = iATR(NULL,0,atr_range,i) * atr_factor;
        }
      else
        {
         DeltaStop=DeltaPrice*Point;
        }
      if(Close[i]==TrStop[i+1])
        {
         TrStop[i]=TrStop[i+1];
        }
      else
        {
         if(Close[i+1]<TrStop[i+1] && Close[i]<TrStop[i+1])
           {
            TrStop[i]=MathMin(TrStop[i+1],Close[i]+DeltaStop);
           }
         else
           {
            if(Close[i+1]>TrStop[i+1] && Close[i]>TrStop[i+1])
              {
               TrStop[i]=MathMax(TrStop[i+1],Close[i]-DeltaStop);
              }
            else
              {
               if(Close[i]>TrStop[i+1]) TrStop[i]=Close[i]-DeltaStop; else TrStop[i]=Close[i]+DeltaStop;
              }
           }
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments