Volatility.Pivot
Download scriptThis tool is designed to track market price movement by identifying and reacting to shifts in volatility. Instead of simply following the price, it functions as a dynamic "trailing" mechanism that adjusts itself based on how much the market is moving at any given moment.
Core Logic and Functionality
The script operates using three main components to determine where the "support" or "resistance" levels should sit:
1. Volatility Measurement The tool first analyzes recent price history to calculate the current market volatility. It uses a standard volatility formula (ATR) to understand how much the price typically swings over a specific period. This ensures that the tool adapts to different market conditions—becoming more sensitive during quiet markets and wider during highly active ones.
2. Dynamic Buffer Calculation The script provides two distinct ways to calculate the "buffer" or safety distance from the price:
- Volatility-Based: It calculates a moving average of the volatility and multiplies it by a specific factor. This creates a breathing zone that expands when the market gets wild and shrinks when the market calms down.
- Fixed-Price Based: Alternatively, it can be set to use a constant, pre-defined price distance regardless of market activity.
3. The Tracking Mechanism (The "Pivot") The primary job of the script is to plot a line that reacts to price action. Here is how the logic flows:
- Stability: If the current price remains consistent with the previous level, the line stays flat.
- Price Breaks: When the price moves significantly enough to break past the current line, the script recalculates the new position.
- Directional Sensitivity: The logic distinguishes between upward and downward movements. If the price is falling below a level, the script looks for the "floor" by taking the lower of the previous support or the current price plus the volatility buffer. If the price is rising above a level, it seeks the "ceiling" by comparing the previous resistance against the current price minus the buffer.
- Crossovers: If the price suddenly jumps across the line (a sharp move), the script immediately resets the line to the new price point, adjusted by the volatility buffer to ensure the new level isn't too tight or too loose.
Summary for the User
Essentially, this script creates a "smart" trailing line. It tries to stay out of the way during minor fluctuations but will "snap" to new levels when the market shows a clear change in direction. By using volatility to set these levels, it helps visualize significant price pivots while filtering out the daily noise of the market.
//+------------------------------------------------------------------+
//| 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 DarkSeaGreen
//---- 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 counted_bars = IndicatorCounted();
int limit;
int i;
double DeltaStop;
limit = Bars;
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